Skip to content

Commit

Permalink
feat: 🎸 add a script to warm the cache
Browse files Browse the repository at this point in the history
it's meant to be called by an external cron jonb for example
  • Loading branch information
severo committed Oct 5, 2021
1 parent 8a011fe commit e854860
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ style:
# The result is benchmark/tmp/report.json (about 40M)
benchmark:
$(MAKE) -C benchmark $(PARALLEL)

warm:
poetry run python src/datasets_preview_backend/warm.py
27 changes: 27 additions & 0 deletions src/datasets_preview_backend/warm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from tqdm.contrib.concurrent import thread_map # type: ignore

from datasets_preview_backend.logger import init_logger
from datasets_preview_backend.queries.datasets import get_datasets
from datasets_preview_backend.queries.rows import get_rows

MAX_THREADS = 5


def call_get_rows(dataset: str) -> None:
try:
get_rows(dataset=dataset)
except Exception:
pass


def warm() -> None:
datasets = [d["dataset"] for d in get_datasets()["datasets"]]

threads = min(MAX_THREADS, len(datasets))

thread_map(call_get_rows, datasets, max_workers=threads, desc="warm the cache (datasets)")


if __name__ == "__main__":
init_logger(log_level="ERROR")
warm()

0 comments on commit e854860

Please sign in to comment.