mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-02-02 05:31:01 -05:00
Merge branch 'dev' into dependabot/bundler/scout_apm-2.6.5
This commit is contained in:
@@ -4,7 +4,14 @@ module CropSearch
|
||||
included do
|
||||
####################################
|
||||
# Elastic search configuration
|
||||
searchkick word_start: %i(name alternate_names scientific_names), case_sensitive: false
|
||||
searchkick word_start: %i(name alternate_names scientific_names),
|
||||
case_sensitive: false,
|
||||
merge_mappings: true,
|
||||
mappings: {
|
||||
properties: {
|
||||
created_at: { type: :integer }
|
||||
}
|
||||
}
|
||||
|
||||
# Special scope to control if it's in the search index
|
||||
scope :search_import, -> { includes(:scientific_names, :photos) }
|
||||
|
||||
@@ -8,7 +8,9 @@ module PhotoCapable
|
||||
scope :has_photos, -> { includes(:photos).where.not(photos: { id: nil }) }
|
||||
|
||||
def default_photo
|
||||
most_liked_photo
|
||||
Rails.cache.fetch("#{cache_key_with_version}/default_photo", expires_in: 8.hours) do
|
||||
most_liked_photo
|
||||
end
|
||||
end
|
||||
|
||||
def most_liked_photo
|
||||
|
||||
@@ -42,14 +42,16 @@ module PredictPlanting
|
||||
end
|
||||
|
||||
def percentage_grown
|
||||
if finished?
|
||||
100
|
||||
elsif !planted?
|
||||
0
|
||||
elsif crop.perennial || finish_predicted_at.nil?
|
||||
nil
|
||||
else
|
||||
calculate_percentage_grown
|
||||
Rails.cache.fetch("#{cache_key_with_version}/percentage_grown", expires_in: 8.hours) do
|
||||
if finished?
|
||||
100
|
||||
elsif !planted?
|
||||
0
|
||||
elsif crop.perennial || finish_predicted_at.nil?
|
||||
nil
|
||||
else
|
||||
calculate_percentage_grown
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class CropSearchService
|
||||
limit: limit,
|
||||
load: false,
|
||||
body: body
|
||||
).response['hits']['hits'].map { |c| c['_source'] }
|
||||
)
|
||||
end
|
||||
|
||||
def self.recent(limit)
|
||||
@@ -37,6 +37,6 @@ class CropSearchService
|
||||
limit: limit,
|
||||
load: false,
|
||||
boost_by: { created_at: { factor: 100 } } # default factor is 1
|
||||
).response['hits']['hits'].map { |c| c['_source'] }
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user