Skip to content

Commit 5f018c9

Browse files
authored
Correct random sort logic
If no sort field is specified in GraphQL the server defaults to date created (descending). This incorrectly weighs the random sort results which creates bias towards newer content. Adding the random sort field corrects this.
1 parent c10e0d2 commit 5f018c9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

plugins/StashRandomButton/random_button.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
async function randomGlobal(entity, idField, redirectPrefix, internalFilter) {
2121
const realEntityPlural = getPlural(entity);
22-
let filter = { per_page: 1 };
22+
let filter = { per_page: 1, sort: "random" };
2323
let variables = { filter };
2424
let filterArg = "";
2525
let filterVar = "";
@@ -45,7 +45,7 @@
4545
if (!totalCount) { alert("No results found."); return; }
4646

4747
const randomIndex = Math.floor(Math.random() * totalCount);
48-
let itemVars = { filter: { per_page: 1, page: randomIndex + 1 } };
48+
let itemVars = { filter: { per_page: 1, page: randomIndex + 1, sort: "random" } };
4949
if (internalFilter) itemVars.internal_filter = internalFilter;
5050
const itemQuery = `
5151
query Find${realEntityPlural}($filter: FindFilterType${filterArg}) {

0 commit comments

Comments
 (0)