Recompute empty similar-player cache
This commit is contained in:
1 parent
56f10f7c29
commit
4c7ca94ee4
2 files changed
+34
No files matched your search
@@ -276,6 +276,39 @@ describe('SimilarPlayerService', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('recomputes when the cached similar-player result is empty', async () => {
|
||||
const currentProfile = createProfile();
|
||||
const candidateProfile = createProfile({
|
||||
puuid: 'newly-indexed-similar-player',
|
||||
score: 0.92,
|
||||
});
|
||||
const findOne = jest.fn(() => createLeanExec(currentProfile));
|
||||
const aggregate = jest.fn(() => createAggregateExec([candidateProfile]));
|
||||
const recommendationFindOne = jest.fn(() =>
|
||||
createSortedLeanExec({
|
||||
profileUpdatedAt: new Date('2026-07-02T00:00:00.000Z'),
|
||||
result: { matches: [] },
|
||||
}),
|
||||
);
|
||||
const updateOne = jest.fn(() => createUpdateExec({ acknowledged: true }));
|
||||
const service = new SimilarPlayerService({
|
||||
getModel: jest.fn((modelKey: string) =>
|
||||
Promise.resolve(
|
||||
modelKey === 'playerProfile'
|
||||
? { findOne, aggregate }
|
||||
: { findOne: recommendationFindOne, updateOne },
|
||||
),
|
||||
),
|
||||
} as unknown as ConnectionService);
|
||||
|
||||
const result = await service.findSimilarPlayers('target-puuid', 420, 10);
|
||||
|
||||
expect(aggregate).toHaveBeenCalledTimes(1);
|
||||
expect(updateOne).toHaveBeenCalledTimes(1);
|
||||
expect(result.matches).toHaveLength(1);
|
||||
expect(result.matches[0]?.puuid).toBe('newly-indexed-similar-player');
|
||||
});
|
||||
|
||||
it('returns a fresh cached similar-player recommendation without running vector search', async () => {
|
||||
const currentProfile = createProfile();
|
||||
const cachedMatch = {
|
||||
|
||||
@@ -427,6 +427,7 @@ export class SimilarPlayerService {
|
||||
): SimilarPlayer[] | null {
|
||||
const matches = recommendation?.result?.matches;
|
||||
if (!Array.isArray(matches)) return null;
|
||||
if (matches.length === 0) return null;
|
||||
if (!matches.every((match) => this.isCachedSimilarPlayer(match))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user