Skip to content

A platform for community discussion. Free, open, simple.

PERF: Add `index_web_hook_events_on_created_at` (#34594)

Alan Guo Xiang Tan5fafb3a55e34
diff --git a/app/models/web_hook_event.rb b/app/models/web_hook_event.rb
index 5b330876ad8..ddcafbb649b 100644
--- a/app/models/web_hook_event.rb
+++ b/app/models/web_hook_event.rb
@@ -33,17 +33,18 @@ end
# Table name: web_hook_events
#
# id :integer not null, primary key
-# web_hook_id :integer not null
+# duration :integer default(0)
# headers :string
# payload :text
-# status :integer default(0)
-# response_headers :string
# response_body :text
-# duration :integer default(0)
+# response_headers :string
+# status :integer default(0)
# created_at :datetime not null
# updated_at :datetime not null
+# web_hook_id :integer not null
#
# Indexes
#
+# index_web_hook_events_on_created_at (created_at)
# index_web_hook_events_on_web_hook_id (web_hook_id)
#
diff --git a/db/migrate/20250828011415_add_index_created_at_on_web_hook_events.rb b/db/migrate/20250828011415_add_index_created_at_on_web_hook_events.rb
new file mode 100644
index 00000000000..38d1865d45b
--- /dev/null
+++ b/db/migrate/20250828011415_add_index_created_at_on_web_hook_events.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+class AddIndexCreatedAtOnWebHookEvents < ActiveRecord::Migration[8.0]
+ disable_ddl_transaction!
+
+ def up
+ execute <<~SQL
+ DROP INDEX CONCURRENTLY IF EXISTS index_web_hook_events_on_created_at
+ SQL
+
+ execute <<~SQL
+ CREATE INDEX CONCURRENTLY index_web_hook_events_on_created_at
+ ON web_hook_events USING btree (created_at)
+ SQL
+ end
+
+ def down
+ execute <<~SQL
+ DROP INDEX CONCURRENTLY IF EXISTS index_web_hook_events_on_created_at
+ SQL
+ end
+end