mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 09:16:22 +00:00
refactor: no es necesario buscar en un array
This commit is contained in:
parent
003d8fa303
commit
4872ddd227
1 changed files with 2 additions and 5 deletions
|
@ -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|
|
||||||
|
|
Loading…
Reference in a new issue