From 4bbdd0b2d0f4e97e3f9e50aadff437b11276e1a9 Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Tue, 2 Apr 2024 21:54:30 +0200 Subject: [PATCH] Add index on Status.remote_id This field is often used in WHERE-clauses in queries that are very slow on bookwyrm.social. --- ...9_status_bookwyrm_st_remote__06aeba_idx.py | 19 +++++++++++++++++++ bookwyrm/models/status.py | 3 +++ 2 files changed, 22 insertions(+) create mode 100644 bookwyrm/migrations/0199_status_bookwyrm_st_remote__06aeba_idx.py diff --git a/bookwyrm/migrations/0199_status_bookwyrm_st_remote__06aeba_idx.py b/bookwyrm/migrations/0199_status_bookwyrm_st_remote__06aeba_idx.py new file mode 100644 index 000000000..5d2513698 --- /dev/null +++ b/bookwyrm/migrations/0199_status_bookwyrm_st_remote__06aeba_idx.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.25 on 2024-04-02 19:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0198_book_search_vector_author_aliases"), + ] + + operations = [ + migrations.AddIndex( + model_name="status", + index=models.Index( + fields=["remote_id"], name="bookwyrm_st_remote__06aeba_idx" + ), + ), + ] diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index f6235dab6..a9c678cb5 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -80,6 +80,9 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): """default sorting""" ordering = ("-published_date",) + indexes = [ + models.Index(fields=["remote_id"]), + ] def save(self, *args, **kwargs): """save and notify"""