Skip to content

Commit

Permalink
OCT-1721: Cache often consecutive DB query.
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-code committed Jul 4, 2024
1 parent 61db329 commit 09a6e86
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/app/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
generate_cache_key,
)

from functools import wraps, partial
from functools import partial
import lru
import threading
import time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing_extensions import deprecated

from app.infrastructure.database.models import PendingEpochSnapshot
from app.extensions import db
from app.extensions import db, cache
from app import exceptions

from decimal import Decimal
Expand All @@ -20,10 +20,12 @@ def get_by_epoch_num(epoch) -> PendingEpochSnapshot:
return snapshot


@cache.memoize(timeout=15)
def get_by_epoch(epoch: int) -> Optional[PendingEpochSnapshot]:
return PendingEpochSnapshot.query.filter_by(epoch=epoch).first()


@cache.memoize(timeout=15)
def get_last_snapshot() -> PendingEpochSnapshot:
snapshot = (
db.session.query(PendingEpochSnapshot)
Expand Down

0 comments on commit 09a6e86

Please sign in to comment.