-
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 #1035 from thunderstore-io/chunky
Chunked package lists
- Loading branch information
Showing
13 changed files
with
686 additions
and
14 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
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
33 changes: 33 additions & 0 deletions
33
django/thunderstore/repository/api/v1/views/listing_index.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.shortcuts import get_object_or_404, redirect | ||
from drf_yasg.utils import swagger_auto_schema # type: ignore | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from thunderstore.community.models import Community | ||
from thunderstore.repository.models import APIV1ChunkedPackageCache | ||
|
||
|
||
class PackageListingIndex(APIView): | ||
""" | ||
Return a blob file containing URLs to package listing chunks. | ||
Client needs to gunzip and JSON parse the blob contents. | ||
/c/{community_id}/api/v1/package-listing-index/ | ||
""" | ||
|
||
@swagger_auto_schema( | ||
tags=["api"], | ||
auto_schema=None, # Hide from API docs for now. | ||
) | ||
def get(self, request: Request, community_identifier: str): | ||
community = get_object_or_404( | ||
Community.objects.listed(), | ||
identifier=community_identifier, | ||
) | ||
cache = APIV1ChunkedPackageCache.get_latest_for_community(community) | ||
|
||
if cache: | ||
return redirect(request.build_absolute_uri(cache.index.data_url)) | ||
|
||
return Response({"error": "No cache available"}, status=503) |
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
59 changes: 59 additions & 0 deletions
59
django/thunderstore/repository/migrations/0052_add_chunked_package_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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Generated by Django 3.1.7 on 2024-05-21 12:09 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("community", "0028_add_cover_image_fields"), | ||
("storage", "0002_add_group"), | ||
("repository", "0051_bigint_file_size"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="APIV1ChunkedPackageCache", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("is_deleted", models.BooleanField(default=False)), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
( | ||
"chunks", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="chunked_package_list_cache", | ||
to="storage.datablobgroup", | ||
), | ||
), | ||
( | ||
"community", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="chunked_package_list_cache", | ||
to="community.community", | ||
), | ||
), | ||
( | ||
"index", | ||
models.OneToOneField( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="chunked_package_indexes", | ||
to="storage.datablob", | ||
), | ||
), | ||
], | ||
options={ | ||
"get_latest_by": "created_at", | ||
}, | ||
), | ||
] |
43 changes: 43 additions & 0 deletions
43
django/thunderstore/repository/migrations/0053_schedule_chunked_package_caching.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 3.1.7 on 2024-05-21 12:10 | ||
|
||
import pytz | ||
from django.db import migrations | ||
|
||
TASK = "thunderstore.repository.tasks.update_chunked_package_caches" | ||
|
||
|
||
def forwards(apps, schema_editor): | ||
CrontabSchedule = apps.get_model("django_celery_beat", "CrontabSchedule") | ||
PeriodicTask = apps.get_model("django_celery_beat", "PeriodicTask") | ||
|
||
schedule, _ = CrontabSchedule.objects.get_or_create( | ||
minute="0", | ||
hour="*", | ||
day_of_week="*", | ||
day_of_month="*", | ||
month_of_year="*", | ||
timezone=pytz.timezone("UTC"), | ||
) | ||
|
||
PeriodicTask.objects.get_or_create( | ||
crontab=schedule, | ||
name="Update APIV1ChunkedPackageCache", | ||
task=TASK, | ||
expire_seconds=300, | ||
) | ||
|
||
|
||
def backwards(apps, schema_editor): | ||
PeriodicTask = apps.get_model("django_celery_beat", "PeriodicTask") | ||
PeriodicTask.objects.filter(task=TASK).delete() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("repository", "0052_add_chunked_package_cache"), | ||
("django_celery_beat", "0014_remove_clockedschedule_enabled"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(forwards, backwards), | ||
] |
24 changes: 24 additions & 0 deletions
24
django/thunderstore/repository/migrations/0054_alter_chunked_package_cache_index.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 3.1.7 on 2024-05-22 09:01 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("storage", "0002_add_group"), | ||
("repository", "0053_schedule_chunked_package_caching"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="apiv1chunkedpackagecache", | ||
name="index", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="chunked_package_indexes", | ||
to="storage.datablob", | ||
), | ||
), | ||
] |
Oops, something went wrong.