Merge branch 'dev' into dependabot/bundler/scout_apm-2.6.5

This commit is contained in:
Daniel O'Connor
2019-12-16 14:33:50 +10:00
committed by GitHub
4 changed files with 23 additions and 12 deletions

View File

@@ -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) }

View File

@@ -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

View File

@@ -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

View File

@@ -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