From 0501ce39cdd22a57b484b48f987dc342bbedf9e6 Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Wed, 3 Apr 2024 21:15:24 +0200 Subject: [PATCH] Add index for looking up User by username --- ...202_user_bookwyrm_us_usernam_b2546d_idx.py | 19 +++++++++++++++++++ bookwyrm/models/user.py | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 bookwyrm/migrations/0202_user_bookwyrm_us_usernam_b2546d_idx.py diff --git a/bookwyrm/migrations/0202_user_bookwyrm_us_usernam_b2546d_idx.py b/bookwyrm/migrations/0202_user_bookwyrm_us_usernam_b2546d_idx.py new file mode 100644 index 000000000..d8666fe3f --- /dev/null +++ b/bookwyrm/migrations/0202_user_bookwyrm_us_usernam_b2546d_idx.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.25 on 2024-04-03 19:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0201_keypair_bookwyrm_ke_remote__472927_idx"), + ] + + operations = [ + migrations.AddIndex( + model_name="user", + index=models.Index( + fields=["username"], name="bookwyrm_us_usernam_b2546d_idx" + ), + ), + ] diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index e24143e8e..8c1b79e45 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -198,6 +198,13 @@ class User(OrderedCollectionPageMixin, AbstractUser): hotp_secret = models.CharField(max_length=32, default=None, blank=True, null=True) hotp_count = models.IntegerField(default=0, blank=True, null=True) + class Meta(AbstractUser.Meta): + """indexes""" + + indexes = [ + models.Index(fields=["username"]), + ] + @property def active_follower_requests(self): """Follow requests from active users"""