Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions classes/core/posterMetadataDb.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const fs = require("fs");
const os = require("os");
const crypto = require("crypto");
const path = require("path");
const Cache = require("./cache");
const MediaCard = require("../cards/MediaCard");
Expand All @@ -22,6 +24,15 @@ const MAX_ENTRIES = 100000;
const MIN_FILE_BYTES = 256;
const DEFAULT_FALLBACK_COUNT = 24;

const POSTER_PICK_INSTANCE_OFFSET = (() => {
const host = String(os.hostname() || "");
let h = 0;
for (let i = 0; i < host.length; i++) {
h = (Math.imul(31, h) + host.charCodeAt(i)) >>> 0;
}
return (h + crypto.randomInt(0, 1000000)) >>> 0;
})();

const SCHEMA_SQL = `
CREATE TABLE IF NOT EXISTS poster_entries (
cache_file TEXT PRIMARY KEY NOT NULL,
Expand Down Expand Up @@ -1067,6 +1078,10 @@ function pickRandomEntries(count, serverKindOpt, hideContentRatings, serverIdsOp
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
const rotateBy = POSTER_PICK_INSTANCE_OFFSET % shuffled.length;
if (rotateBy > 0) {
return shuffled.slice(rotateBy).concat(shuffled.slice(0, rotateBy)).slice(0, Math.min(count, shuffled.length));
}
return shuffled.slice(0, Math.min(count, shuffled.length));
}

Expand Down
Loading
Loading