fix(plaza): correct similar recall query params

This commit is contained in:
john
2026-07-07 16:55:38 +08:00
parent ea4c6b707c
commit fd364dbbeb
2 changed files with 53 additions and 2 deletions
+1 -1
View File
@@ -404,7 +404,7 @@ export function createPlazaRecommendService(
const recallSimilar = async (profile, userId, categorySlug) => { const recallSimilar = async (profile, userId, categorySlug) => {
const seeds = [...profile.likedPostIds].slice(0, 12); const seeds = [...profile.likedPostIds].slice(0, 12);
if (seeds.length === 0) return []; if (seeds.length === 0) return [];
const params = ['published', ...seeds]; const params = [...seeds];
let filter = ` AND r1.post_id IN (${seeds.map(() => '?').join(',')})`; let filter = ` AND r1.post_id IN (${seeds.map(() => '?').join(',')})`;
if (userId) { if (userId) {
filter += ' AND r2.user_id <> ?'; filter += ' AND r2.user_id <> ?';
+52 -1
View File
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict'; import assert from 'node:assert/strict';
import test from 'node:test'; import test from 'node:test';
import { createPlazaEventService } from './plaza-events.mjs'; import { createPlazaEventService } from './plaza-events.mjs';
import { recommendInternals } from './plaza-recommend.mjs'; import { createPlazaRecommendService, recommendInternals } from './plaza-recommend.mjs';
test('plaza events: dwell tiers increase signal weight', () => { test('plaza events: dwell tiers increase signal weight', () => {
const { eventSignal } = createPlazaEventService({ query: async () => [[]] }).internals; const { eventSignal } = createPlazaEventService({ query: async () => [[]] }).internals;
@@ -64,6 +64,57 @@ test('plaza recommend: cold start interleaves categories', () => {
assert.notEqual(ordered[0].category_slug, ordered[1].category_slug); assert.notEqual(ordered[0].category_slug, ordered[1].category_slug);
}); });
test('plaza recommend: recallSimilar binds seeds before viewer id', async () => {
let similarParams = null;
const pool = {
async query(sql, params) {
if (sql.includes('FROM plaza_reactions r1')) {
similarParams = params;
return [[]];
}
if (sql.includes('SELECT tags FROM plaza_posts WHERE id IN')) {
return [[{ tags: '[]' }]];
}
if (sql.includes('FROM plaza_posts pp')) {
return [[]];
}
return [[]];
},
};
const recommend = createPlazaRecommendService(pool, {
eventService: {
async getProfile() {
return {
categoryWeights: {},
tagWeights: {},
authorWeights: {},
feedCategoryWeights: {},
likedPostIds: new Set(['seed-post']),
dislikedPostIds: new Set(),
dislikedCategorySlugs: new Set(),
followedAuthorIds: new Set(),
seenPostIds: new Set(),
deepSeenPostIds: new Set(),
eventCount: 1,
profileVersion: 7,
};
},
},
formatPostRow(row) {
return { id: row.id };
},
loadViewerReactions: async () => new Map(),
});
await recommend.listRecommendedFeed({
viewerId: 'viewer-1',
sessionId: 'session-1',
limit: 20,
});
assert.deepEqual(similarParams, ['seed-post', 'viewer-1', 80]);
});
test('plaza events: dislike marks category as disliked', () => { test('plaza events: dislike marks category as disliked', () => {
const { emptyProfile } = createPlazaEventService({ query: async () => [[]] }).internals; const { emptyProfile } = createPlazaEventService({ query: async () => [[]] }).internals;
const profile = emptyProfile(); const profile = emptyProfile();