Skip to content

Commit

Permalink
Include id in index, reset on mutate
Browse files Browse the repository at this point in the history
  • Loading branch information
svevang committed Oct 4, 2023
1 parent e5d6cf4 commit 62f6855
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions app/models/episode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Episode < ApplicationRecord
class_name: "Apple::PodcastDelivery"
has_many :apple_podcast_delivery_files, through: :apple_podcast_deliveries, source: :podcast_delivery_files,
class_name: "Apple::PodcastDeliveryFile"
has_many :apple_episode_delivery_statuses, dependent: :destroy, class_name: "Apple::EpisodeDeliveryStatus"
has_many :apple_episode_delivery_statuses, -> { order(created_at: :desc) }, dependent: :destroy, class_name: "Apple::EpisodeDeliveryStatus"

validates :podcast_id, :guid, presence: true
validates :title, presence: true
Expand Down Expand Up @@ -115,7 +115,7 @@ def apple_delivery_file_errors
end

def apple_episode_delivery_status
apple_episode_delivery_statuses.reset.order(created_at: :desc).first
apple_episode_delivery_statuses.order(created_at: :desc).first
end

def apple_needs_delivery?
Expand All @@ -126,10 +126,14 @@ def apple_needs_delivery?

def apple_needs_delivery!
apple_episode_delivery_statuses.create!(delivered: false)
apple_episode_delivery_statuses.reset
apple_episode_delivery_status
end

def apple_has_delivery!
apple_episode_delivery_statuses.create!(delivered: true)
apple_episode_delivery_statuses.reset
apple_episode_delivery_status
end

def self.generate_item_guid(podcast_id, episode_guid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def change
t.datetime :created_at, null: false
end

execute('CREATE INDEX "index_apple_episode_delivery_statuses_on_episode_id_created_at" ON "apple_episode_delivery_statuses" ("episode_id", "created_at") INCLUDE (delivered);')
execute('CREATE INDEX "index_apple_episode_delivery_statuses_on_episode_id_created_at" ON "apple_episode_delivery_statuses" ("episode_id", "created_at") INCLUDE (delivered, id);')

reversible do |dir|
dir.up do
Expand Down
4 changes: 2 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 62f6855

Please sign in to comment.