Improve application responsiveness and background processing

This commit is contained in:
2026-10-04 19:56:06 -04:00
parent 1392a082da
commit ed004ddbcf
70 changed files with 1324 additions and 345 deletions
+10 -12
View File
@@ -74,15 +74,15 @@ it('keeps lifetime profiles available when selected history is empty or an effic
const { db } = await import('../../src/lib/server/db/index.js');
addMatches(db(), '101', 4);
const { load } = await import('../../src/routes/leaderboard/players/[guid]/+page.server.js');
const filtered = load({ params: { guid: '101' }, url: new URL('http://localhost/leaderboard/players/101?game=t6&map=t6%3Atown&offset=25') });
const filtered = await load({ params: { guid: '101' }, url: new URL('http://localhost/leaderboard/players/101?game=t6&map=t6%3Atown&offset=25') });
expect(filtered).toMatchObject({ returnTo: '/leaderboard',
profile: { stats: { gamesPlayed: 4, kills: 40 }, matches: [], matchesTotal: 0, offset: 0 },
scope: { game: 't6', map: 't6:town', metric: 'highestRound', entry: null } });
const unqualified = load({ params: { guid: '101' }, url: new URL('http://localhost/leaderboard/players/101?metric=averageKills') });
const unqualified = await load({ params: { guid: '101' }, url: new URL('http://localhost/leaderboard/players/101?metric=averageKills') });
expect(unqualified).toMatchObject({ profile: { matchesTotal: 4, stats: { gamesPlayed: 4 } },
scope: { game: '', map: '', metric: 'averageKills', entry: null } });
addMatches(db(), '101', 1);
expect(load({ params: { guid: '101' }, url: new URL('http://localhost/leaderboard/players/101?metric=averageKills') }))
expect(await load({ params: { guid: '101' }, url: new URL('http://localhost/leaderboard/players/101?metric=averageKills') }))
.toMatchObject({ scope: { entry: { guid: '101', rank: 1, averageKills: 10, gamesPlayed: 5 } } });
});
@@ -93,13 +93,13 @@ it('loads canonical navigation context while keeping source search and paginatio
const { load } = await import('../../src/routes/leaderboard/players/[guid]/+page.server.js');
const url = new URL('http://localhost/leaderboard/players/101?game=t5&map=t5%3Atheater&metric=kills');
url.searchParams.set('returnTo', '/leaderboard?game=t5&map=t5%3Atheater&metric=kills&q=101&offset=50&unknown=drop');
const loaded = load({ params: { guid: '101' }, url });
const loaded = await load({ params: { guid: '101' }, url });
expect(loaded.returnTo).toBe('/leaderboard?game=t5&map=t5%3Atheater&metric=kills&q=101&offset=50');
expect(loaded.scope).toMatchObject({ game: 't5', map: 't5:theater', metric: 'kills', entry: { guid: '101', rank: 2 } });
expect(loaded.profile.offset).toBe(0);
url.searchParams.set('returnTo', 'https://external.invalid/leaderboard');
expect(load({ params: { guid: '101' }, url }).returnTo).toBe('/leaderboard');
const defaults = load({ params: { guid: '101' }, url: new URL('http://localhost/leaderboard/players/101') });
expect((await load({ params: { guid: '101' }, url })).returnTo).toBe('/leaderboard');
const defaults = await load({ params: { guid: '101' }, url: new URL('http://localhost/leaderboard/players/101') });
expect(defaults).toMatchObject({ returnTo: '/leaderboard', scope: { game: '', map: '', metric: 'highestRound' } });
});
@@ -108,13 +108,11 @@ it('rejects invalid filter parameters and retains existing offset normalization
addMatches(db(), '101', 30);
const { load } = await import('../../src/routes/leaderboard/players/[guid]/+page.server.js');
for (const query of ['game=t7', 'game=', 'metric=', 'metric=unknown', `map=${'x'.repeat(1025)}`]) {
expect(() => load({ params: { guid: '101' }, url: new URL(`http://localhost/leaderboard/players/101?${query}`) }))
.toThrow(expect.objectContaining({ status: 400 }));
await expect(load({ params: { guid: '101' }, url: new URL(`http://localhost/leaderboard/players/101?${query}`) })).rejects.toThrow(expect.objectContaining({ status: 400 }));
}
for (const query of ['offset=garbage', 'offset=-1', 'offset=1.5', 'offset=Infinity']) {
expect(load({ params: { guid: '101' }, url: new URL(`http://localhost/leaderboard/players/101?${query}`) }).profile.offset).toBe(0);
expect((await load({ params: { guid: '101' }, url: new URL(`http://localhost/leaderboard/players/101?${query}`) })).profile.offset).toBe(0);
}
expect(load({ params: { guid: '101' }, url: new URL('http://localhost/leaderboard/players/101?offset=999') }).profile.offset).toBe(25);
expect(() => load({ params: { guid: 'missing' }, url: new URL('http://localhost/leaderboard/players/missing?game=t5') }))
.toThrow(expect.objectContaining({ status: 404 }));
expect((await load({ params: { guid: '101' }, url: new URL('http://localhost/leaderboard/players/101?offset=999') })).profile.offset).toBe(25);
await expect(load({ params: { guid: 'missing' }, url: new URL('http://localhost/leaderboard/players/missing?game=t5') })).rejects.toThrow(expect.objectContaining({ status: 404 }));
});