mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-02 19:02:28 +00:00
Merge pull request #2115 from PR0M3TH3AN/perf-feed-engine-normalization-9770844072882054108
⚡ Optimize feed engine normalization performance
This commit is contained in:
1 file changed
+24
-1
+24
-1
@@ -3,6 +3,8 @@
|
||||
import { isPlainObject } from "./utils.js";
|
||||
import { userLogger } from "../utils/logger.js";
|
||||
|
||||
const NORMALIZED_MARKER = Symbol("FeedItemNormalized");
|
||||
|
||||
const DEFAULT_FEED_CONFIG = Object.freeze({
|
||||
timeWindow: null,
|
||||
actorFilters: [],
|
||||
@@ -58,19 +60,40 @@ function normalizeDto(candidate) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (candidate[NORMALIZED_MARKER]) {
|
||||
return candidate;
|
||||
}
|
||||
|
||||
const video = candidate.video ?? null;
|
||||
const pointer = candidate.pointer ?? null;
|
||||
const metadata = isPlainObject(candidate.metadata)
|
||||
? { ...candidate.metadata }
|
||||
: {};
|
||||
|
||||
return { video, pointer, metadata };
|
||||
const normalized = { video, pointer, metadata };
|
||||
normalized[NORMALIZED_MARKER] = true;
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function normalizeItems(items) {
|
||||
if (!Array.isArray(items)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let dirty = false;
|
||||
const len = items.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const candidate = items[i];
|
||||
if (!candidate || !candidate[NORMALIZED_MARKER]) {
|
||||
dirty = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dirty) {
|
||||
return items;
|
||||
}
|
||||
|
||||
const normalized = [];
|
||||
for (const candidate of items) {
|
||||
const dto = normalizeDto(candidate);
|
||||
|
||||
Reference in new issue
Block a user