Initial curated chimera source from a8ae5b1db07fb49926c94585e2718e5130330974
This commit is contained in:
commit
c737a37f71
531 files changed
+119270
No files matched your search
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
const test = require('node:test');
|
||||
const { createV3LibraryService } = require('../../src/services/v3-library-service');
|
||||
const { runBenchmark } = require('../../scripts/check-v3-query-performance');
|
||||
|
||||
function mockDatabase() {
|
||||
const queries = [];
|
||||
return { queries, runQuery(sql) {
|
||||
queries.push(sql);
|
||||
if (/SELECT COUNT\(\*\) AS total FROM titles/.test(sql)) return [{ total: 5000 }];
|
||||
if (/FROM titles t LEFT JOIN games g/.test(sql)) {
|
||||
const limit = Number(sql.match(/LIMIT (\d+)/)?.[1] || 0);
|
||||
return Array.from({ length: limit }, (_, index) => ({ v3_title_pk: index + 1, v3_external_title_id: `PPSA${String(index + 1).padStart(5, '0')}`, v3_platform: 'ps5', v3_name: `Title ${index + 1}`, v3_sort_name: `Title ${index + 1}`, v3_metadata_json: '{}', v3_metadata_source: 'fixture', v3_metadata_seen_at: 1 }));
|
||||
}
|
||||
return [];
|
||||
} };
|
||||
}
|
||||
|
||||
test('v3 main view pushes bounds and filters into SQL with constant query count', () => {
|
||||
const db = mockDatabase(); const page = createV3LibraryService(db).list({ limit: 10_000, offset: 40, search: "title' safe", platform: 'ps5', installed: true, backed_up: true });
|
||||
assert.equal(page.limit, 200); assert.equal(page.offset, 40); assert.equal(page.items.length, 200); assert.equal(page.total, 5000); assert.equal(page.hasMore, true);
|
||||
assert.equal(db.queries.length, 7, 'title page must use one count, one page and five bounded bulk queries');
|
||||
assert.match(db.queries[0], /LOWER\(/); assert.match(db.queries[0], /EXISTS \(SELECT 1 FROM console_installs/); assert.match(db.queries[0], /EXISTS \(SELECT 1 FROM local_copies/);
|
||||
for (const query of db.queries.filter(sql => /\n\s*FROM (?:local_copies|console_installs)|FROM v_(?:title_availability|protection_health)/.test(sql))) {
|
||||
assert.match(query, /title_id IN \(/, 'child materialization must be limited to current page IDs');
|
||||
assert.ok((query.match(/\d+/g) || []).length <= 210, 'bounded title ID fan-out exceeded');
|
||||
}
|
||||
});
|
||||
|
||||
test('trophy and media views expose explicit bounded pagination contracts', () => {
|
||||
const psn = fs.readFileSync(path.join(__dirname, '../../src/services/trophy-snapshot-service.js'), 'utf8');
|
||||
const local = fs.readFileSync(path.join(__dirname, '../../src/services/local-trophy-inventory-service.js'), 'utf8');
|
||||
const media = fs.readFileSync(path.join(__dirname, '../../src/server/register-functional-modules.js'), 'utf8');
|
||||
assert.match(psn, /Math\.min\(100[\s\S]*LIMIT @limit OFFSET @offset/);
|
||||
assert.match(local, /Math\.min\(100[\s\S]*LIMIT @limit OFFSET @offset/);
|
||||
assert.match(media, /Math\.min\(500[\s\S]*pageItems = sourceItems\.slice\(offset, offset \+ limit\)/);
|
||||
});
|
||||
|
||||
test('large v3 fixture uses required indexes within the query budget', async () => {
|
||||
const result = await runBenchmark({ titleCount: 5000, maxMs: 2000 });
|
||||
assert.equal(result.pageSize, 200); assert.match(result.plans.titles, /idx_titles_listing_sort/i);
|
||||
assert.match(result.plans.copies, /idx_local_copies_title_state_id/i); assert.match(result.plans.installs, /idx_console_installs_title_state_id/i);
|
||||
});
|
||||
Reference in new issue
Block a user