Skip to content

fix: match filters with several tag names and apply limit per filter - #792

Merged
cameri merged 4 commits into
cameri:mainfrom
Anshumancanrock:fix/multi-tag-filters
Sep 30, 2026
Merged

cameri merged 4 commits into
cameri:mainfrom
Anshumancanrock:fix/multi-tag-filters

Conversation

@Anshumancanrock

Copy link
Copy Markdown
Collaborator

Description

Tag filters were matched through one left join on event_tags, with every tag condition on the same joined row. A filter with two tag names ({"#e":[...],"#p":[...]}) needed a single row to carry both, so it never matched a stored event, and ids plus a tag filter failed on an ambiguous event_id. Each tag name now gets its own EXISTS subquery. Since EXISTS never returns an event twice, REQ no longer needs DISTINCT and COUNT uses count(*).

With several filters, query.union(subqueries, true) left the first filter's ORDER BY and LIMIT after the UNION, capping a REQ at that filter's limit (500 by default) and breaking a COUNT whose first filter had one. Filters are now combined with knex.union(queries, true), which wraps each of them, and REQ keeps sorting the combined rows like the first filter.

Related Issue

Closes #789

Motivation and Context

Both bugs fail quietly on common queries. A REQ with two tag names gets EOSE and nothing else, and [{"kinds":[0],"authors":[pk],"limit":1},{"kinds":[1],"authors":[pk]}] returns a single event. The unit tests compare generated SQL and no integration scenario used two tag names in one filter or a limit on the first of several filters, so neither shape was caught.

@changeset-bot

changeset-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fd4ce5a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Rewrites event filtering query logic in the database layer.

The reviewed changes appear safe to merge.

Summary

This PR changes event tag matching to use one EXISTS condition per tag name and wraps each filter query so its limit applies to that filter. It also adds REQ and COUNT integration scenarios and updates SQL unit tests.

Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Filters] --> B[Build one query per filter]
  B --> C[Match tag names with EXISTS]
  C --> D[Apply each filter's limit]
  D --> E[Union filter results]
  E --> F[Return events or count]
Loading

Reviews (1) · Last reviewed commit: "fix: match filters with several tag name..."

@coveralls

coveralls commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 73.013% (-0.01%) from 73.024% — Anshumancanrock:fix/multi-tag-filters into cameri:main

@cameri
cameri merged commit 29dbed8 into cameri:main Sep 30, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Filters with two tag names match nothing and the first filter's limit caps multi-filter queries

4 participants