-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1003 from thunderstore-io/more-caches
Several cache improvements
- Loading branch information
Showing
12 changed files
with
160 additions
and
158 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
"default", | ||
"legacy", | ||
"profiles", | ||
"downloads", | ||
] | ||
|
||
|
||
|
25 changes: 18 additions & 7 deletions
25
django/thunderstore/core/management/commands/clear_cache.py
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 |
---|---|---|
@@ -1,14 +1,25 @@ | ||
from django.conf import settings | ||
from django.core.cache import cache | ||
from django.core.management.base import BaseCommand, CommandError | ||
from django.core.cache import caches | ||
from django.core.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Clears all configured caches" | ||
|
||
def add_arguments(self, parser) -> None: | ||
parser.add_argument("caches", nargs="*", default=["default"]) | ||
parser.add_argument("--all", default=False, action="store_true") | ||
|
||
def handle(self, *args, **kwargs): | ||
if settings.CACHES: | ||
cache.clear() | ||
self.stdout.write("Caches cleared!") | ||
else: | ||
raise CommandError("No caches are currently configured") | ||
names = kwargs.get("caches", ["default"]) | ||
if kwargs.get("all") is True: | ||
names = settings.CACHES.keys() | ||
|
||
for name in names: | ||
if name in settings.CACHES: | ||
self.stdout.write(f"Clearing cache: {name}") | ||
caches[name].clear() | ||
else: | ||
self.stderr.write(f"Cache {name} not found, unable to clear") | ||
|
||
self.stdout.write("All done!") |
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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .caches import * | ||
from .downloads import * | ||
from .files import * | ||
from .submission import * |
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,23 @@ | ||
from datetime import datetime | ||
|
||
from celery import shared_task | ||
from django.db import transaction | ||
from django.db.models import F | ||
|
||
from thunderstore.core.settings import CeleryQueues | ||
from thunderstore.metrics.models import PackageVersionDownloadEvent | ||
from thunderstore.repository.models import PackageVersion | ||
|
||
TASK_LOG_VERSION_DOWNLOAD = "thunderstore.repository.tasks.log_version_download" | ||
|
||
|
||
@shared_task(queue=CeleryQueues.LogDownloads, name=TASK_LOG_VERSION_DOWNLOAD) | ||
def log_version_download(version_id: int, timestamp: str): | ||
with transaction.atomic(): | ||
PackageVersionDownloadEvent.objects.create( | ||
version_id=version_id, | ||
timestamp=datetime.fromisoformat(timestamp), | ||
) | ||
PackageVersion.objects.filter(id=version_id).update( | ||
downloads=F("downloads") + 1 | ||
) |
Oops, something went wrong.