mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-05 04:12:25 +00:00
Merge pull request #2296 from PR0M3TH3AN/perf/kids-scoring-caching-11674686208806463085
⚡ Optimize feed scoring by caching normalized tag sets
This commit is contained in:
1 file changed
+10
-2
@@ -14,6 +14,8 @@ const DEFAULT_WEIGHTS = Object.freeze({
|
||||
|
||||
const DEFAULT_FRESHNESS_HALF_LIFE_DAYS = 14;
|
||||
|
||||
const videoTagCache = new WeakMap();
|
||||
|
||||
const AGE_GROUP_DEFAULTS = Object.freeze({
|
||||
toddler: {
|
||||
maxDurationSeconds: 5 * 60,
|
||||
@@ -51,11 +53,16 @@ function clamp01(value) {
|
||||
}
|
||||
|
||||
function normalizeTagSetFromVideo(video) {
|
||||
const normalized = new Set();
|
||||
if (!video || typeof video !== "object") {
|
||||
return normalized;
|
||||
return new Set();
|
||||
}
|
||||
|
||||
if (videoTagCache.has(video)) {
|
||||
return videoTagCache.get(video);
|
||||
}
|
||||
|
||||
const normalized = new Set();
|
||||
|
||||
const addTag = (rawTag) => {
|
||||
if (typeof rawTag !== "string") {
|
||||
return;
|
||||
@@ -80,6 +87,7 @@ function normalizeTagSetFromVideo(video) {
|
||||
}
|
||||
}
|
||||
|
||||
videoTagCache.set(video, normalized);
|
||||
return normalized;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user