Skip to content

fixed aloglia cache_key#3825

Merged
arkid15r merged 8 commits intoOWASP:mainfrom
Mr-Rahul-Paul:fix#3815
Feb 10, 2026
Merged

fixed aloglia cache_key#3825
arkid15r merged 8 commits intoOWASP:mainfrom
Mr-Rahul-Paul:fix#3815

Conversation

@Mr-Rahul-Paul
Copy link
Contributor

Resolves #3815

Summary

  • Fixed cache key collision in Algolia search, facetFilters was extracted and used in queries but missing from the cache key.
  • Two searches with the same query but different filters returned identical cached results.

Proposed change

Include facetFilters in the Algolia cache key. Filters are sorted and joined with _ to match existing key style and consistency.

Checklist

  • Required: I followed the contributing workflow
  • Required: I verified that my code works as intended and resolves the issue as described
  • Required: I ran make check-test locally: all warnings addressed, tests passed
  • I used AI for code, documentation, tests, or communication related to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Recomputes the Algolia cache key to include a serialized filters_key when facet_filters is non-empty (using json.dumps(facet_filters, sort_keys=True)), and adds tests validating caching behavior across differing and identical facet_filters.

Changes

Cohort / File(s) Summary
Algolia cache key update
backend/apps/core/api/internal/algolia.py
When facet_filters is non-empty, compute filters_key = json.dumps(facet_filters, sort_keys=True) and append it to the existing cache_key so cache get/set include facet filters.
Tests for caching & facet filters
backend/tests/apps/core/api/internal/algolia_test.py
Added imports for CACHE_TTL_IN_SECONDS, CACHE_PREFIX; introduced _build_request helper; added tests asserting different facet_filters produce different results and identical requests hit cache (single backend call).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fixed aloglia cache_key' directly addresses the main change in the PR, which is fixing the cache key collision by including facetFilters.
Description check ✅ Passed The description clearly explains the cache key collision issue, the proposed solution, and references the linked issue #3815, directly matching the changeset.
Linked Issues check ✅ Passed The PR fully addresses issue #3815 by including facetFilters in the cache key using json.dumps with sorted keys, resolving the cache collision issue described in the linked issue.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the cache key collision issue: modifications to algolia.py implement the fix, and test additions validate the new behavior.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Confidence score: 3/5

  • There is a concrete crash risk in backend/apps/core/api/internal/algolia.py when facetFilters includes nested arrays (valid Algolia OR syntax), which would raise a TypeError at runtime.
  • Because this affects valid query shapes, there is some user-impacting regression risk despite being localized.
  • Pay close attention to backend/apps/core/api/internal/algolia.py - handling of nested facetFilters arrays.
Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="backend/apps/core/api/internal/algolia.py">

<violation number="1" location="backend/apps/core/api/internal/algolia.py:54">
P1: This will crash with `TypeError` if `facetFilters` contains nested arrays (valid Algolia OR syntax like `[["genre:comedy", "genre:drama"]]`). Consider using `json.dumps(facet_filters, sort_keys=True)` or flattening nested arrays before joining to handle all valid Algolia filter formats.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@backend/apps/core/api/internal/algolia.py`:
- Around line 54-58: The cache-key generation using
"_".join(sorted(facet_filters)) is collision-prone and will break on nested
lists; replace it by serializing facet_filters into a deterministic JSON string
and use that as filters_key (e.g., json.dumps(facet_filters, separators=(",",
":"), sort_keys=True)) so filters_key is collision-free and handles nested
structures; update where filters_key is referenced (the cache_key construction
that combines CACHE_PREFIX, index_name, query, page, limit, and filters_key) to
use this JSON-serialized value.

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add/update tests.

@Mr-Rahul-Paul
Copy link
Contributor Author

Mr-Rahul-Paul commented Feb 8, 2026

Hi ! @arkid15r do you want me to use json.dumps for filter keys as suggested by the bots ?
image
Thanks

@arkid15r
Copy link
Collaborator

arkid15r commented Feb 9, 2026

Hi ! @arkid15r do you want me to use json.dumps for filter keys as suggested by the bots ? image Thanks

The suggestion sounds reasonable.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@backend/tests/apps/core/api/internal/algolia_test.py`:
- Around line 252-253: Fix the inline comment and file ending: update the
comment before the assertion to include a space after the `#` and spaces around
the `=` (e.g., change `#backend only called once = caching worked` to `# backend
only called once = caching worked` or better `# backend only called once =
caching worked`), and ensure the test file ends with a trailing newline
character so Ruff W292 is satisfied; the assertion call to locate the spot is
`mock_get_search_results.assert_called_once()`.
🧹 Nitpick comments (1)
backend/tests/apps/core/api/internal/algolia_test.py (1)

31-45: Consider using _build_request in existing tests for consistency.

The helper is well-structured, but the existing test_algolia_search_valid_request (lines 70–81) and test_algolia_search_invalid_request (lines 163–173) still manually construct mock requests with the same structure. Consider refactoring them to use _build_request to reduce duplication.

@Mr-Rahul-Paul
Copy link
Contributor Author

Added 2 tests to verify that different facet filters produce different results while identical requests return cached results.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 9, 2026
@Mr-Rahul-Paul
Copy link
Contributor Author

ready for review @arkid15r

@sonarqubecloud
Copy link

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please start running make check locally.

@arkid15r arkid15r enabled auto-merge February 10, 2026 05:06
@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.38%. Comparing base (9c593c5) to head (8605180).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3825      +/-   ##
==========================================
+ Coverage   95.37%   95.38%   +0.01%     
==========================================
  Files         463      463              
  Lines       14541    14543       +2     
  Branches     2060     2017      -43     
==========================================
+ Hits        13868    13872       +4     
+ Misses        329      328       -1     
+ Partials      344      343       -1     
Flag Coverage Δ
backend 95.67% <100.00%> (+0.01%) ⬆️
frontend 94.61% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
backend/apps/core/api/internal/algolia.py 84.00% <100.00%> (+4.83%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c593c5...8605180. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arkid15r arkid15r added this pull request to the merge queue Feb 10, 2026
Merged via the queue into OWASP:main with commit 31047c7 Feb 10, 2026
35 checks passed
@Mr-Rahul-Paul
Copy link
Contributor Author

Mr-Rahul-Paul commented Feb 10, 2026

Noted , Thanks!

arkid15r added a commit that referenced this pull request Feb 10, 2026
* Run make update

* Clean up snapshot generated videos

* Update backend/data/nest.dump

* feat(ui): revamp corporate supporters carousel (Infinite Marquee + Dark Mode fix) (#3837)

* feat(ui): revamp corporate supporters carousel (Infinite Marquee + Dark Mode fix)

* fix: resolve failing test case

* fix: add fallback text for unnamed sponsors

* docs: add docstrings to satisfy coverage requirements

* Run make check and fix tests.

---------

Co-authored-by: Kate <kate@kgthreads.com>

* Fix/redundant typescript assertion (#3834)

* Fix Sonar S4325 by narrowing session user fields instead of casting

* Fix unused ExtendedSession in mentorship page

* fix: redundant-typescript-assertion

* Fix stale latest date displayed in Project Health Dashboard metrics (#3842)

* Fixed latest date in proejct health dashboard

* updated order

* Update code

* Update code

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>

* feat: improve backend test coverage to 96% (#3840)

* feat: improve backend test coverage to 96%

* fix comments

* fix issues

* fix issue

* fix cubic-dev-ai comments

* Update code

* Fix tests

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>

* Fix: merge consecutive RUN instructions in frontend Dockerfile (#3644)

* Fix: merge consecutive RUN instructions in frontend Dockerfile

* fix: comment Dockerfile note to prevent syntax error

* Update code

* Update code

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>

* Fix 'is_merged' not being available on the Issue (#3843)

* Fix 'is_merged' not being available on the Issue

* Update code

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>

* CI:  Add ansible-lint workflow for Ansible playbooks (#3796)

* ci: add ansible-lint workflow

Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>

* Update .github/workflows/lint-ansible.yaml

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* ci: add ansible-lint make target and workflow

Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>

* ci: add ansible-lint pre-commit hook

Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>

* fix: whitespace & version

Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>

* Update Makefile

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* ci: enable ansible-lint scanning and add requirements.yml

Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>

* chore(ansible):align linting and module usage

Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>

* ci(ansible): install collections before deploy playbooks

Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>

* Update code

* Update code

* Update .github/workflows/run-ci-cd.yaml

---------

Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>

* Fix ElevenLabs API error (#3861)

* use default liam voice

* bump speed by 0.10

---------

Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>

* Add Ime Iyonsi to MENTORS.md (#3866)

* Add mentor profile for Ime Iyonsi

Added Ime Iyonsi's mentor profile.

* Fix GitHub link for Ime Iyonsi

Corrected GitHub link for Ime Iyonsi.

* Update code

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>

* Update MENTORS.md

* Enabled Strict Mode (#3776)

* Enabled Strict Mode

* fixed ai review

* fix

* fixed review

* fix

* update test

* Update code

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>

* Resolve case-sensitivity in QueryParser to support Chapters/Members search (#3844)

* resolve query parser blocker

* use case_sensitive flag in QueryParser

* feat: add case_sensitive option to QueryParser and update tests

* Update code

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>

* Update dependencies (#3874)

* Update dependencies

* Bump django-ninja version

* fix(proxy): pin nginx and certbot images (#3848)

* fix(proxy): pin nginx and certbot images

Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>

* fix stable verssions

Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>

---------

Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>

* Update docker-compose/proxy/compose.yaml

* Update backend/pyproject.toml

* Update ansible lint configuration (#3880)

* Update .github/ansible/.ansible-lint.yaml

* Improve frontend test coverage above 80% and add missing test files (#3864)

* Imrove test coverage to 80% and added test

* Fixed coderabbit review

* update code

* fixed coderabbit ai

* fixed soanrqube warning

* fixed review

* update

* fixed aloglia cache_key (#3825)

* fixed aloglia cache_key

* change separator val to be semicolon (;)

* Update code

* add tests + use json filters

* add trailing newline

* Update code

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>

* fix: remove unused className prop from AnchorTitle component (#3822)

* fix: remove unused className prop from AnchorTitle component

Fixes #3805

The className prop was defined in AnchorTitleProps but never used
in the component implementation. Removing it resolves Sonar rule
typescript:S6767 and improves code maintainability.

* fix: use className prop instead of removing it

- Added className back to AnchorTitleProps interface
- Accept className parameter in component
- Apply className to root div element
- Resolves reviewer feedback on PR #3822

* Update code

---------

Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>

---------

Signed-off-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>
Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
Co-authored-by: Yashraj Pahuja <yashrajpahuja9999@gmail.com>
Co-authored-by: Kate <kate@kgthreads.com>
Co-authored-by: CodeAritraDhank <aritradhank21@gmail.com>
Co-authored-by: Anurag Yadav <143180737+anurag2787@users.noreply.github.com>
Co-authored-by: Harshit Verma <harshit1092004@gmail.com>
Co-authored-by: Arkadii Yakovets <2201626+arkid15r@users.noreply.github.com>
Co-authored-by: Shuban Mutagi <shubanmutagi55@gmail.com>
Co-authored-by: Muhammad Hassaan Saleem <iamhassaans@gmail.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
Co-authored-by: emaybu <152900874+emaybu@users.noreply.github.com>
Co-authored-by: sai chethana <saichethanavesireddy@gmail.com>
Co-authored-by: Rahul Paul <179798584+Mr-Rahul-Paul@users.noreply.github.com>
Co-authored-by: Lavanya <lavanyayadawad30@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Algolia cache key missing facetFilters

2 participants