From 4d5a30d9533cec6f137cf25b85fad9415e122cfe Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Wed, 3 Apr 2024 21:11:27 +0200 Subject: [PATCH] Add index for looking up KeyPair by remote id --- ..._keypair_bookwyrm_ke_remote__472927_idx.py | 19 +++++++++++++++++++ bookwyrm/models/user.py | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 bookwyrm/migrations/0201_keypair_bookwyrm_ke_remote__472927_idx.py diff --git a/bookwyrm/migrations/0201_keypair_bookwyrm_ke_remote__472927_idx.py b/bookwyrm/migrations/0201_keypair_bookwyrm_ke_remote__472927_idx.py new file mode 100644 index 000000000..e3d27a11b --- /dev/null +++ b/bookwyrm/migrations/0201_keypair_bookwyrm_ke_remote__472927_idx.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.25 on 2024-04-03 19:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0200_status_bookwyrm_st_thread__cf064f_idx"), + ] + + operations = [ + migrations.AddIndex( + model_name="keypair", + index=models.Index( + fields=["remote_id"], name="bookwyrm_ke_remote__472927_idx" + ), + ), + ] diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 89fd39b73..e24143e8e 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -509,6 +509,13 @@ class KeyPair(ActivitypubMixin, BookWyrmModel): activity_serializer = activitypub.PublicKey serialize_reverse_fields = [("owner", "owner", "id")] + class Meta: + """indexes""" + + indexes = [ + models.Index(fields=["remote_id"]), + ] + def get_remote_id(self): # self.owner is set by the OneToOneField on User return f"{self.owner.remote_id}/#main-key"