Sort completed bubbles by most recently completed first

This commit is contained in:
Jorge Manrubia
2025-04-04 15:34:18 +02:00
parent 0e3f756a27
commit f437aecf00
5 changed files with 54 additions and 30 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ class BubblesController < ApplicationController
def index
@considering_bubbles = @filter.bubbles.considering.load_async
@doing_bubbles = @filter.bubbles.doing.load_async
@popped_bubbles = @filter.with(indexed_by: "popped").bubbles.limit(RECENTLY_POPPED_LIMIT).load_async
@popped_bubbles = @filter.with(indexed_by: "popped").bubbles.recently_popped_first.limit(RECENTLY_POPPED_LIMIT).load_async
end
def create
+1
View File
@@ -9,6 +9,7 @@ module Bubble::Poppable
scope :popped, -> { joins(:pop) }
scope :active, -> { where.missing(:pop) }
scope :recently_popped_first, -> { popped.order("pops.created_at": :desc) }
scope :due_to_be_popped, -> { considering.where(last_active_at: ..AUTO_POP_AFTER.ago) }
end
@@ -0,0 +1,5 @@
class AddIndexToSortPopsByRecency < ActiveRecord::Migration[8.1]
def change
add_index :pops, %i[ bubble_id created_at ]
end
end
Generated
+3 -2
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.1].define(version: 2025_04_04_083727) do
ActiveRecord::Schema[8.1].define(version: 2025_04_04_133310) do
create_table "accesses", force: :cascade do |t|
t.integer "bucket_id", null: false
t.datetime "created_at", null: false
@@ -113,7 +113,7 @@ ActiveRecord::Schema[8.1].define(version: 2025_04_04_083727) do
t.datetime "created_at", null: false
t.integer "creator_id", null: false
t.date "due_on"
t.datetime "last_active_at", null: false
t.datetime "last_active_at"
t.integer "stage_id"
t.text "status", default: "creating", null: false
t.string "title"
@@ -249,6 +249,7 @@ ActiveRecord::Schema[8.1].define(version: 2025_04_04_083727) do
t.string "reason", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.index ["bubble_id", "created_at"], name: "index_pops_on_bubble_id_and_created_at"
t.index ["bubble_id"], name: "index_pops_on_bubble_id", unique: true
t.index ["user_id"], name: "index_pops_on_user_id"
end
+44 -27
View File
@@ -468,6 +468,16 @@ columns:
default_function:
collation:
comment:
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
auto_increment:
name: last_active_at
cast_type: *3
sql_type_metadata: *4
'null': true
default:
default_function:
collation:
comment:
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
auto_increment:
name: stage_id
@@ -499,16 +509,6 @@ columns:
collation:
comment:
- *9
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
auto_increment:
name: last_active_at
cast_type: *3
sql_type_metadata: *4
'null': false
default:
default_function:
collation:
comment:
buckets:
- *5
- &32 !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
@@ -760,6 +760,7 @@ columns:
default_function:
collation:
comment:
- *6
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
auto_increment:
name: label
@@ -770,12 +771,21 @@ columns:
default_function:
collation:
comment:
- *6
- *9
pops:
- *5
- *25
- *6
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
auto_increment:
name: reason
cast_type: *7
sql_type_metadata: *8
'null': false
default:
default_function:
collation:
comment:
- *9
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
auto_increment:
@@ -787,16 +797,6 @@ columns:
default_function:
collation:
comment:
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
auto_increment:
name: reason
cast_type: *7
sql_type_metadata: *8
'null': false
default:
default_function:
collation:
comment:
reactions:
- *5
- !ruby/object:ActiveRecord::ConnectionAdapters::SQLite3::Column
@@ -1354,11 +1354,10 @@ indexes:
bubbles:
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
table: bubbles
name: index_bubbles_on_last_active_at_and_status
name: index_bubbles_on_stage_id
unique: false
columns:
- last_active_at
- status
- stage_id
lengths: {}
orders: {}
opclasses: {}
@@ -1371,10 +1370,11 @@ indexes:
valid: true
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
table: bubbles
name: index_bubbles_on_stage_id
name: index_bubbles_on_last_active_at_and_status
unique: false
columns:
- stage_id
- last_active_at
- status
lengths: {}
orders: {}
opclasses: {}
@@ -1856,6 +1856,23 @@ indexes:
comment:
valid: true
pops:
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
table: pops
name: index_pops_on_bubble_id_and_created_at
unique: false
columns:
- bubble_id
- created_at
lengths: {}
orders: {}
opclasses: {}
where:
type:
using:
include:
nulls_not_distinct:
comment:
valid: true
- !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition
table: pops
name: index_pops_on_user_id
@@ -2106,4 +2123,4 @@ indexes:
nulls_not_distinct:
comment:
valid: true
version: 20250404083727
version: 20250404133310