mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-07-30 17:59:13 -04:00
Exclude null compatibility scores when ordering profiles by compatibility. Update compute-scores logic to delete invalid score rows instead of setting them to null. Add corresponding test coverage.
This commit is contained in:
@@ -659,6 +659,10 @@ export const loadProfiles = async (props: profileQueryType, db?: SupabaseDirectC
|
||||
: '90 days',
|
||||
}),
|
||||
|
||||
// Precomputed scores can be nulled out (e.g. after the user deletes their last shared
|
||||
// prompt) instead of the row being removed — don't surface those as matches.
|
||||
orderByParam === 'compatibility_score' && where('cs.score IS NOT NULL'),
|
||||
|
||||
// Exclude profiles that the requester has chosen to hide
|
||||
userId &&
|
||||
where(
|
||||
|
||||
@@ -319,4 +319,20 @@ describe('loadProfiles', () => {
|
||||
expect(profilesModule.loadProfiles(props)).rejects.toThrowError('Incompatible with user ID')
|
||||
})
|
||||
})
|
||||
|
||||
describe('when ordering by compatibility score', () => {
|
||||
it('excludes profiles whose precomputed score was nulled out', async () => {
|
||||
;(mockPg.map as jest.Mock).mockResolvedValue([])
|
||||
;(mockPg.one as jest.Mock).mockResolvedValue(0)
|
||||
|
||||
await profilesModule.loadProfiles({
|
||||
orderBy: 'compatibility_score',
|
||||
compatibleWithUserId: 'user-1',
|
||||
})
|
||||
|
||||
const [query] = mockPg.map.mock.calls[0]
|
||||
|
||||
expect(query).toContain('cs.score IS NOT NULL')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -29,11 +29,12 @@ export async function recomputeCompatibilityScoresForUser(
|
||||
// Load all answers for the target user
|
||||
const answersSelf = await getAnswersForUser(userId)
|
||||
|
||||
// If the user has no answered questions, set the score to null
|
||||
// If the user has no answered questions, there's no valid score to keep for any pair
|
||||
// involving them — remove the rows rather than nulling them out, so a row's existence
|
||||
// always means "we have a valid score for this pair".
|
||||
if (!hasAnsweredQuestions(answersSelf)) {
|
||||
await pg.none(
|
||||
`update compatibility_scores
|
||||
set score = null
|
||||
`delete from compatibility_scores
|
||||
where user_id_1 = $1
|
||||
or user_id_2 = $1`,
|
||||
[userId],
|
||||
|
||||
Reference in New Issue
Block a user