From b5b4f11056e22049a342041af0c6372af57640a8 Mon Sep 17 00:00:00 2001
From: Karina Kwiatek <kjk@kjk.dog>
Date: Sat, 18 Feb 2023 15:32:29 +0100
Subject: [PATCH] Add index for `answers.created_at`

This improves query time for the public timeline
---
 .../20230218142952_add_index_for_created_at_on_answers.rb  | 7 +++++++
 db/schema.rb                                               | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 db/migrate/20230218142952_add_index_for_created_at_on_answers.rb

diff --git a/db/migrate/20230218142952_add_index_for_created_at_on_answers.rb b/db/migrate/20230218142952_add_index_for_created_at_on_answers.rb
new file mode 100644
index 00000000..536db607
--- /dev/null
+++ b/db/migrate/20230218142952_add_index_for_created_at_on_answers.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+class AddIndexForCreatedAtOnAnswers < ActiveRecord::Migration[6.1]
+  def change
+    add_index :answers, :created_at, order: :desc
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 33418a33..4d54a933 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2023_02_12_181044) do
+ActiveRecord::Schema.define(version: 2023_02_18_142952) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -49,6 +49,7 @@ ActiveRecord::Schema.define(version: 2023_02_12_181044) do
     t.datetime "updated_at"
     t.integer "smile_count", default: 0, null: false
     t.datetime "pinned_at"
+    t.index ["created_at"], name: "index_answers_on_created_at", order: :desc
     t.index ["question_id"], name: "index_answers_on_question_id"
     t.index ["user_id", "created_at"], name: "index_answers_on_user_id_and_created_at"
     t.index ["user_id", "pinned_at"], name: "index_answers_on_user_id_and_pinned_at"