Merge pull request #2318 from PR0M3TH3AN/feed-engine-optimization-13596960870183920240

⚡ Optimize feed engine normalization overhead
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-02-10 14:25:27 -05:00
commit d951e74920
5 files changed
+29 -12

No files matched your search

+8 -1
View File
@@ -1,6 +1,6 @@
// js/feedEngine/engine.js
import { isPlainObject } from "./utils.js";
import { isPlainObject, markAsNormalized, NORMALIZED_ARRAY_MARKER } from "./utils.js";
import { userLogger } from "../utils/logger.js";
const NORMALIZED_MARKER = Symbol("FeedItemNormalized");
@@ -80,6 +80,10 @@ function normalizeItems(items) {
return [];
}
if (items[NORMALIZED_ARRAY_MARKER]) {
return items;
}
let dirty = false;
const len = items.length;
for (let i = 0; i < len; i++) {
@@ -91,6 +95,7 @@ function normalizeItems(items) {
}
if (!dirty) {
markAsNormalized(items);
return items;
}
@@ -101,6 +106,8 @@ function normalizeItems(items) {
normalized.push(dto);
}
}
markAsNormalized(normalized);
return normalized;
}
+2 -2
View File
@@ -1,7 +1,7 @@
// js/feedEngine/kidsAudienceFilterStage.js
import nostrService from "../services/nostrService.js";
import { toSet } from "./utils.js";
import { toSet, markAsNormalized } from "./utils.js";
const DEFAULT_DISALLOWED_WARNINGS = [
"nudity",
@@ -156,6 +156,6 @@ export function createKidsAudienceFilterStage({
results.push(item);
}
return results;
return markAsNormalized(results);
};
}
+4 -3
View File
@@ -1,6 +1,7 @@
// js/feedEngine/sorters.js
import { normalizeHashtag } from "../utils/hashtagNormalization.js";
import { markAsNormalized } from "./utils.js";
export function createChronologicalSorter({
direction = "desc",
@@ -133,7 +134,7 @@ export function createChronologicalSorter({
: bId.localeCompare(aId);
});
return copy;
return markAsNormalized(copy);
};
}
@@ -455,7 +456,7 @@ export function createExploreDiversitySorter({
}
const orderedRest = [...rest].sort(compareByTimestampId);
return selected.concat(orderedRest);
return markAsNormalized(selected.concat(orderedRest));
};
}
@@ -502,6 +503,6 @@ export function createKidsScoreSorter({
});
}
return copy;
return markAsNormalized(copy);
};
}
+6 -6
View File
@@ -11,7 +11,7 @@ import moderationService from "../services/moderationService.js";
import logger from "../utils/logger.js";
import { dedupeToNewestByRoot } from "../utils/videoDeduper.js";
import { normalizeHashtag } from "../utils/hashtagNormalization.js";
import { isPlainObject, toSet } from "./utils.js";
import { isPlainObject, toSet, markAsNormalized } from "./utils.js";
const FEED_HIDE_BYPASS_NAMES = new Set(["home", "recent"]);
@@ -90,7 +90,7 @@ export function createDedupeByRootStage({
});
}
return keep;
return markAsNormalized(keep);
};
}
@@ -420,7 +420,7 @@ function filterByTagPreferences({
results.push(item);
}
return results;
return markAsNormalized(results);
}
export function createBlacklistFilterStage({
@@ -472,7 +472,7 @@ export function createBlacklistFilterStage({
results.push(item);
}
return results;
return markAsNormalized(results);
};
}
@@ -538,7 +538,7 @@ export function createWatchHistorySuppressionStage({
results.push(item);
}
return results;
return markAsNormalized(results);
};
}
@@ -1364,6 +1364,6 @@ export function createModerationStage({
results.push(item);
}
return results;
return markAsNormalized(results);
};
}
+9
View File
@@ -2,6 +2,15 @@
import { normalizeHashtag } from "../utils/hashtagNormalization.js";
export const NORMALIZED_ARRAY_MARKER = Symbol("FeedItemsNormalized");
export function markAsNormalized(items) {
if (Array.isArray(items)) {
items[NORMALIZED_ARRAY_MARKER] = true;
}
return items;
}
export function isPlainObject(value) {
if (value === null || typeof value !== "object") {
return false;