Compare commits

...

2 commits

Author SHA1 Message Date
13a0362e6d Use PetState#updated_at for the supported pose cache key, not latest ID
This is because labeling poses with the Support tools *should*
invalidate the `PetState.all_supported_poses` cache! But the previous
cache key would only invalidate when a new pet state is *added*, not
when one is *edited*.
2024-10-07 17:56:42 -07:00
fe67211fdf Add created_at/updated_at to PetState
This has just been absent for too long! We've lost a lot of data about
when poses were first modeled, which is a shame.

But I want this in now, because I was just doing caching on
/rainbow-pool.json, and realized that _labeling_ poses is another way
pet states can update rather than just being created!

So we need an `updated_at` field, to be able to quickly detect edits
that require us to invalidate the cache on
`PetState.all_supported_poses`. I'll do that next!
2024-10-07 17:54:54 -07:00
3 changed files with 9 additions and 2 deletions

View file

@ -211,7 +211,7 @@ class PetState < ApplicationRecord
end
def self.last_updated_key
PetState.maximum(:id)
PetState.maximum(:updated_at)
end
def self.all_supported_poses

View file

@ -0,0 +1,5 @@
class AddTimestampsToPetStates < ActiveRecord::Migration[7.2]
def change
add_timestamps :pet_states, null: true
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.2].define(version: 2024_10_03_004726) do
ActiveRecord::Schema[7.2].define(version: 2024_10_08_004715) do
create_table "alt_styles", charset: "utf8mb4", collation: "utf8mb4_unicode_520_ci", force: :cascade do |t|
t.integer "species_id", null: false
t.integer "color_id", null: false
@ -219,6 +219,8 @@ ActiveRecord::Schema[7.2].define(version: 2024_10_03_004726) do
t.boolean "labeled", default: false, null: false
t.boolean "glitched", default: false, null: false
t.string "artist_neopets_username"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["pet_type_id"], name: "pet_states_pet_type_id"
end