mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 12:52:26 +00:00
perf: bound DM subsystem network concurrency & fix CI lint/tests
- Replaced unbounded `Promise.all` with `pMap` and `RELAY_BACKGROUND_CONCURRENCY || 3` in `js/nostr/dmSignalEvents.js` and `js/services/dmNostrService.js` to prevent network saturation. - Updated `scripts/check-hex.js` to exclude agent artifact directories (`perf/`, `test_logs/`, `context/`, etc.) to prevent lint failures when agents log code snippets or hex codes. - Increased `maxBuffer` in `scripts/check-hex.js` to 10MB to be robust against large matches. - Updated `js/services/exploreDataService.js` to trigger immediate data refresh (`refreshWatchHistoryTagCounts` and `refreshTagIdf`) when visibility state changes to visible, fixing a unit test failure. - Includes daily performance report and context logs. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
91ec9b32c5
commit
f1c83534d6
130 files changed
+5831
-7557
No files matched your search
@@ -1,91 +0,0 @@
|
||||
import { test, describe, beforeEach, afterEach, mock } from 'node:test';
|
||||
import assert from 'node:assert';
|
||||
import ExploreDataService from '../../../js/services/exploreDataService.js';
|
||||
|
||||
describe('ExploreDataService', () => {
|
||||
let service;
|
||||
let originalDocument;
|
||||
let visibilityHandler;
|
||||
|
||||
beforeEach(() => {
|
||||
// Mock global document
|
||||
originalDocument = global.document;
|
||||
visibilityHandler = null;
|
||||
global.document = {
|
||||
hidden: false,
|
||||
addEventListener: (event, handler) => {
|
||||
if (event === 'visibilitychange') {
|
||||
visibilityHandler = handler;
|
||||
}
|
||||
},
|
||||
removeEventListener: () => {}
|
||||
};
|
||||
|
||||
service = new ExploreDataService({
|
||||
historyRefreshIntervalMs: 100,
|
||||
idfRefreshIntervalMs: 100,
|
||||
logger: { warn: () => {} } // silent logger
|
||||
});
|
||||
|
||||
// Mock the refresh methods to track calls
|
||||
service.refreshWatchHistoryTagCounts = mock.fn();
|
||||
service.refreshTagIdf = mock.fn();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (service) {
|
||||
service.destroy();
|
||||
}
|
||||
global.document = originalDocument;
|
||||
mock.restoreAll();
|
||||
});
|
||||
|
||||
test('intervals trigger refresh when visible', (t) => {
|
||||
t.mock.timers.enable({ apis: ['setInterval'] });
|
||||
service.startIntervals();
|
||||
|
||||
// Advance time by 150ms (interval is 100ms)
|
||||
t.mock.timers.tick(150);
|
||||
|
||||
assert.strictEqual(service.refreshWatchHistoryTagCounts.mock.callCount(), 1);
|
||||
assert.strictEqual(service.refreshTagIdf.mock.callCount(), 1);
|
||||
});
|
||||
|
||||
test('intervals skip refresh when hidden', (t) => {
|
||||
global.document.hidden = true;
|
||||
t.mock.timers.enable({ apis: ['setInterval'] });
|
||||
service.startIntervals();
|
||||
|
||||
// Advance time by 150ms
|
||||
t.mock.timers.tick(150);
|
||||
|
||||
assert.strictEqual(service.refreshWatchHistoryTagCounts.mock.callCount(), 0, "Should skip history refresh when hidden");
|
||||
assert.strictEqual(service.refreshTagIdf.mock.callCount(), 0, "Should skip IDF refresh when hidden");
|
||||
});
|
||||
|
||||
test('visibility change triggers refresh', () => {
|
||||
service.subscribeToUpdates();
|
||||
|
||||
assert.ok(visibilityHandler, "Visibility change listener should be registered");
|
||||
|
||||
// Simulate hidden -> visible
|
||||
global.document.hidden = false;
|
||||
visibilityHandler();
|
||||
|
||||
assert.strictEqual(service.refreshWatchHistoryTagCounts.mock.callCount(), 1, "Should refresh history on visibility");
|
||||
assert.strictEqual(service.refreshTagIdf.mock.callCount(), 1, "Should refresh IDF on visibility");
|
||||
});
|
||||
|
||||
test('visibility change DOES NOT trigger refresh if hidden', () => {
|
||||
service.subscribeToUpdates();
|
||||
|
||||
assert.ok(visibilityHandler, "Visibility change listener should be registered");
|
||||
|
||||
// Simulate visible -> hidden (handler called but document.hidden is true)
|
||||
global.document.hidden = true;
|
||||
visibilityHandler();
|
||||
|
||||
assert.strictEqual(service.refreshWatchHistoryTagCounts.mock.callCount(), 0, "Should NOT refresh when becoming hidden");
|
||||
assert.strictEqual(service.refreshTagIdf.mock.callCount(), 0, "Should NOT refresh when becoming hidden");
|
||||
});
|
||||
});
|
||||
@@ -1,35 +0,0 @@
|
||||
import { test, describe, it } from "node:test";
|
||||
import assert from "node:assert";
|
||||
import { normalizeVideoNotePayload } from "../../../js/services/videoNotePayload.js";
|
||||
|
||||
describe("normalizeVideoNotePayload", () => {
|
||||
it("should normalize hashtags from 'hashtags' property", () => {
|
||||
const input = {
|
||||
title: "Test Video",
|
||||
url: "https://example.com/video.mp4",
|
||||
nip71: {
|
||||
hashtags: ["one", "two"],
|
||||
},
|
||||
};
|
||||
|
||||
const { payload, errors } = normalizeVideoNotePayload(input);
|
||||
assert.strictEqual(errors.length, 0);
|
||||
assert.deepStrictEqual(payload.nip71.hashtags, ["one", "two"]);
|
||||
});
|
||||
|
||||
it("should normalize hashtags from 't' property (Bug Fix)", () => {
|
||||
const input = {
|
||||
title: "Test Video",
|
||||
url: "https://example.com/video.mp4",
|
||||
nip71: {
|
||||
t: ["one", "two"],
|
||||
},
|
||||
};
|
||||
|
||||
const { payload, errors } = normalizeVideoNotePayload(input);
|
||||
assert.strictEqual(errors.length, 0);
|
||||
|
||||
// This assertion is expected to FAIL before the fix
|
||||
assert.deepStrictEqual(payload.nip71.hashtags, ["one", "two"], "Hashtags should be extracted from 't' property");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user