Review count() implementation - consider FT.AGGREGATE
Open
Nobody has claimed this yet.
enhancement
performance
- Dominant language
- Python
- Stars
- 1.3k
- Forks
- 128
- PR merge metrics
- No merged PRs in 30d
Description
Summary
The current FindQuery.count() implementation uses FT.SEARCH with LIMIT 0 0 and nocontent=True:
async def count(self):
query = self.copy(offset=0, limit=0, nocontent=True)
result = await query.execute(exhaust_results=True, return_raw_result=True)
return result[0]
This works, but FT.AGGREGATE with a count reducer may be a better approach.
Why FT.AGGREGATE might be better
- Purpose-built for aggregations -
FT.AGGREGATEis designed for operations like counting, grouping, etc. - More flexible - Could support
count()with grouping (e.g., count by category) - Potentially more efficient - Aggregation pipeline is optimized for this use case
Example with FT.AGGREGATE
FT.AGGREGATE idx * GROUPBY 0 REDUCE COUNT 0 AS total
This returns just the count without any document data.
Tasks
- Benchmark current
FT.SEARCH LIMIT 0 0vsFT.AGGREGATEfor count - Evaluate if
FT.AGGREGATEprovides any performance benefits - Consider adding grouped count support (e.g.,
Model.find().count(group_by="category"))
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the FindQuery.count() implementation shown in the issue and review how it currently executes FT.SEARCH. Benchmark that approach against the proposed FT.AGGREGATE count, then assess whether grouped counts should be included. Done means the performance comparison and implementation scope have a documented conclusion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, redis
- Domain
- databases
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100