diff --git a/daras_ai_v2/glossary.py b/daras_ai_v2/glossary.py index f7eb1dd05..02af4fbd0 100644 --- a/daras_ai_v2/glossary.py +++ b/daras_ai_v2/glossary.py @@ -50,7 +50,7 @@ def glossary_resource(f_url: str = DEFAULT_GLOSSARY_URL, max_tries=3): # make sure we don't exceed the max number of glossary resources allowed by GCP (we add a safety buffer of 100 for local development) if created and GlossaryResource.objects.count() > MAX_GLOSSARY_RESOURCES - 100: - for gloss in GlossaryResource.objects.order_by("useage_count", "last_updated")[ + for gloss in GlossaryResource.objects.order_by("usage_count", "last_updated")[ :10 ]: try: @@ -77,7 +77,7 @@ def glossary_resource(f_url: str = DEFAULT_GLOSSARY_URL, max_tries=3): raise e finally: GlossaryResource.objects.filter(pk=resource.pk).update( - useage_count=F("useage_count") + 1 + usage_count=F("usage_count") + 1 ) diff --git a/glossary_resources/migrations/0001_initial.py b/glossary_resources/migrations/0001_initial_squashed.py similarity index 51% rename from glossary_resources/migrations/0001_initial.py rename to glossary_resources/migrations/0001_initial_squashed.py index d15e01403..36a7225b3 100644 --- a/glossary_resources/migrations/0001_initial.py +++ b/glossary_resources/migrations/0001_initial_squashed.py @@ -1,7 +1,8 @@ -# Generated by Django 4.2.5 on 2023-09-20 00:54 +# Generated by Django 4.2.6 on 2023-10-18 19:47 import bots.custom_fields from django.db import migrations, models +import uuid class Migration(migrations.Migration): @@ -11,7 +12,7 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name="GlossaryResources", + name="GlossaryResource", fields=[ ( "id", @@ -26,12 +27,21 @@ class Migration(migrations.Migration): "f_url", bots.custom_fields.CustomURLField(max_length=2048, unique=True), ), - ("uses", models.IntegerField(default=0)), - ("last_used", models.DateTimeField(auto_now=True)), - ("times_locked_for_read", models.IntegerField(default=0)), + ("usage_count", models.IntegerField(default=0)), + ("last_updated", models.DateTimeField(auto_now=True)), + ( + "glossary_name", + models.UUIDField(default=uuid.uuid4, editable=False, unique=True), + ), ], options={ - "ordering": ["uses", "last_used"], + "ordering": ["usage_count", "last_updated"], + "indexes": [ + models.Index( + fields=["usage_count", "last_updated"], + name="glossary_re_usage_c_d82f17_idx", + ) + ], }, ), ] diff --git a/glossary_resources/migrations/0002_glossaryresources_glossary_name.py b/glossary_resources/migrations/0002_glossaryresources_glossary_name.py deleted file mode 100644 index d3c2a0f9d..000000000 --- a/glossary_resources/migrations/0002_glossaryresources_glossary_name.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 4.2.5 on 2023-09-20 01:42 - -from django.db import migrations, models -import uuid - - -class Migration(migrations.Migration): - dependencies = [ - ("glossary_resources", "0001_initial"), - ] - - operations = [ - migrations.AddField( - model_name="glossaryresources", - name="glossary_name", - field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True), - ), - ] diff --git a/glossary_resources/migrations/0003_remove_glossaryresources_times_locked_for_read.py b/glossary_resources/migrations/0003_remove_glossaryresources_times_locked_for_read.py deleted file mode 100644 index 0bfd5269c..000000000 --- a/glossary_resources/migrations/0003_remove_glossaryresources_times_locked_for_read.py +++ /dev/null @@ -1,16 +0,0 @@ -# Generated by Django 4.2.5 on 2023-09-20 03:25 - -from django.db import migrations - - -class Migration(migrations.Migration): - dependencies = [ - ("glossary_resources", "0002_glossaryresources_glossary_name"), - ] - - operations = [ - migrations.RemoveField( - model_name="glossaryresources", - name="times_locked_for_read", - ), - ] diff --git a/glossary_resources/models.py b/glossary_resources/models.py index 292e63e1b..7253aeccf 100644 --- a/glossary_resources/models.py +++ b/glossary_resources/models.py @@ -5,23 +5,23 @@ class GlossaryResource(models.Model): f_url = CustomURLField(unique=True) - useage_count = models.IntegerField(default=0) + usage_count = models.IntegerField(default=0) last_updated = models.DateTimeField(auto_now=True) glossary_name = models.UUIDField(unique=True, default=uuid.uuid4, editable=False) class Meta: - ordering = ["useage_count", "last_updated"] + ordering = ["usage_count", "last_updated"] indexes = [ models.Index( fields=[ - "useage_count", + "usage_count", "last_updated", ] ), ] def __str__(self): - return f"{self.f_url} ({self.useage_count} uses)" + return f"{self.f_url} ({self.usage_count} uses)" def get_clean_name(self): return str(self.glossary_name).lower()