Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cache aggregates by owner results until they are updated #693

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Psycojoker
Copy link
Collaborator

@Psycojoker Psycojoker commented Jan 31, 2025

Optimize aggregates API route using caching

Related Clickup or Jira tickets : ALEPH-363

Self proofreading checklist

  • Is my code clear enough and well documented
  • Are my files well typed
  • New translations have been added or updated if new strings have been introduced in the frontend
  • Database migrations file are included
  • Are there enough tests
  • Documentation has been included (for new feature)

Changes

Introduce a small in memory cache based on defaultdict because aiocache requires async and most db related methods aren't async so we can't use it.

We cache on get_aggregates_by_owner call and invalidate the cache on PostgreSQL after_update and after_delete events to ensure we don't miss any update/delete.

How to test

Running the tests should be enough, otherwise you just hit the aggregates API endpoint several time to raise the cache and wait for an aggregate to be updated to see if it works.

@Psycojoker Psycojoker force-pushed the cache-nodes-aggregates branch from 3310c98 to 6f3b217 Compare January 31, 2025 03:41
@Psycojoker
Copy link
Collaborator Author

Right now this is using ORM events, it should be good but I'm not 100 sure, maybe we need to switch to PostgreSQL event triggers instead to ensure that event if another process works on an aggregate the cache will be invalidated?

@Psycojoker Psycojoker marked this pull request as ready for review January 31, 2025 03:49
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.

1 participant