Skip to content

Commit

Permalink
fixed typo and squashed migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi committed Oct 18, 2023
1 parent 5f0d646 commit 588b4a5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 46 deletions.
4 changes: 2 additions & 2 deletions daras_ai_v2/glossary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
)


Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -11,7 +12,7 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name="GlossaryResources",
name="GlossaryResource",
fields=[
(
"id",
Expand All @@ -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",
)
],
},
),
]

This file was deleted.

This file was deleted.

8 changes: 4 additions & 4 deletions glossary_resources/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 588b4a5

Please sign in to comment.