Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/jobs/jobs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,9 @@ export class JobsService {
]);
const configs = new JobFilterConfigsEntity({
...(await this.addTeamRange(values)),
tags: popularTags.map(tag => tag.name),
// The scoped values already contain valid tags. Popularity only narrows
// their ordering/selection and must not take down every filter on failure.
...(popularTags ? { tags: popularTags.map(tag => tag.name) } : {}),
}).getProperties();
await this.cacheManager?.set(
cacheKey,
Expand Down
19 changes: 11 additions & 8 deletions src/postgres/tag.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,23 @@ export class TagRepository {
GROUP BY tag_slug
HAVING count(DISTINCT job.job_node_id) >= 1
AND count(DISTINCT job.job_node_id) < $1
), canonical_tags AS MATERIALIZED (
-- Resolve each tag once. A lateral ORDER BY id / LIMIT lookup can
-- scan the graph primary key separately for every popular tag.
SELECT DISTINCT ON (node.properties ->> 'normalizedName')
node.id,
node.properties,
node.properties ->> 'normalizedName' AS tag_slug
FROM graph_nodes node
WHERE node.label = 'Tag'
ORDER BY node.properties ->> 'normalizedName', node.id
), ranked AS MATERIALIZED (
SELECT
tag.id AS canonical_id,
tag.properties,
popularity.job_count
FROM popularity
JOIN LATERAL (
SELECT node.id, node.properties
FROM graph_nodes node
WHERE node.label = 'Tag'
AND node.properties ->> 'normalizedName' = popularity.tag_slug
ORDER BY node.id
LIMIT 1
) tag ON true
JOIN canonical_tags tag ON tag.tag_slug = popularity.tag_slug
)
SELECT properties
FROM ranked
Expand Down
Loading