-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 add a script to warm the cache
it's meant to be called by an external cron jonb for example
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |