5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-23 12:46:21 +00:00

refactor: no es necesario buscar en un array

This commit is contained in:
f 2024-02-02 12:44:38 -03:00
parent 003d8fa303
commit 4872ddd227
No known key found for this signature in database

View file

@ -11,7 +11,6 @@ class Site
has_many :indexed_posts, dependent: :destroy has_many :indexed_posts, dependent: :destroy
MODIFIED_STATUSES = %i[added modified renamed].freeze MODIFIED_STATUSES = %i[added modified renamed].freeze
DELETED_STATUSES = %i[deleted].freeze
LOCALE_FROM_PATH = /\A_/.freeze LOCALE_FROM_PATH = /\A_/.freeze
def blob_service def blob_service
@ -71,7 +70,7 @@ class Site
# Obtiene todos los archivos a reindexar # Obtiene todos los archivos a reindexar
# #
# @return [Array<Rugged::Delta>] # @return [Array<Rugged::Diff::Delta>]
def indexable_posts def indexable_posts
@indexable_posts ||= @indexable_posts ||=
diff_with_head.each_delta.select do |delta| diff_with_head.each_delta.select do |delta|
@ -84,9 +83,7 @@ class Site
# Elimina los artículos eliminados o que cambiaron de ubicación # Elimina los artículos eliminados o que cambiaron de ubicación
# del índice # del índice
def remove_deleted_posts! def remove_deleted_posts!
indexable_posts.select do |delta| indexable_posts.select(&:deleted?).each do |delta|
DELETED_STATUSES.include? delta.status
end.each do |delta|
locale, path = locale_and_path_from(delta.old_file[:path]) locale, path = locale_and_path_from(delta.old_file[:path])
indexed_posts.destroy_by(locale: locale, path: path).tap do |destroyed_posts| indexed_posts.destroy_by(locale: locale, path: path).tap do |destroyed_posts|