Skip to content

Commit fe217e7

Browse files
committed
Optimisation: index columns to improve searching, filtering and finding associated tasks
1 parent fb73396 commit fe217e7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class AddIndexesToTodoroTasks < ActiveRecord::Migration[8.0]
2+
def change
3+
add_index :todoro_task_lists, [:taskable_type, :taskable_id]
4+
add_index :todoro_tasks, :status
5+
add_index :todoro_tasks, :expiry_date
6+
end
7+
end

spec/todoapp/db/schema.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.0].define(version: 2025_02_14_105918) do
13+
ActiveRecord::Schema[8.0].define(version: 2025_02_15_024110) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_catalog.plpgsql"
1616

@@ -35,6 +35,7 @@
3535
t.datetime "created_at", null: false
3636
t.datetime "updated_at", null: false
3737
t.index ["taskable_type", "taskable_id"], name: "index_todoro_task_lists_on_taskable"
38+
t.index ["taskable_type", "taskable_id"], name: "index_todoro_task_lists_on_taskable_type_and_taskable_id"
3839
end
3940

4041
create_table "todoro_tasks", force: :cascade do |t|
@@ -45,6 +46,8 @@
4546
t.bigint "task_list_id", null: false
4647
t.datetime "created_at", null: false
4748
t.datetime "updated_at", null: false
49+
t.index ["expiry_date"], name: "index_todoro_tasks_on_expiry_date"
50+
t.index ["status"], name: "index_todoro_tasks_on_status"
4851
t.index ["task_list_id"], name: "index_todoro_tasks_on_task_list_id"
4952
t.check_constraint "status::text = ANY (ARRAY['pending'::character varying, 'completed'::character varying]::text[])", name: "status_check"
5053
end

0 commit comments

Comments
 (0)