mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-29 04:02:17 -04:00
One per person on home page
This commit is contained in:
committed by
Brenda Wallace
parent
42cce210c0
commit
5fbdd577d6
@@ -49,12 +49,24 @@ module SearchHarvests
|
||||
end
|
||||
|
||||
def self.homepage_records(limit)
|
||||
search('*', limit: limit,
|
||||
where: {
|
||||
photos_count: { gt: 0 }
|
||||
},
|
||||
boost_by: [:created_at],
|
||||
load: false)
|
||||
records = []
|
||||
owners = []
|
||||
1..limit.times do
|
||||
where = {
|
||||
photos_count: { gt: 0 },
|
||||
owner_id: { not: owners }
|
||||
}
|
||||
one_record = search('*',
|
||||
limit: 1,
|
||||
where: where,
|
||||
boost_by: [:created_at],
|
||||
load: false).first
|
||||
return records if one_record.nil?
|
||||
|
||||
owners << one_record.owner_id
|
||||
records << one_record
|
||||
end
|
||||
records
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,46 +18,64 @@ module SearchPlantings
|
||||
|
||||
def search_data
|
||||
{
|
||||
slug: slug,
|
||||
active: active,
|
||||
finished: finished?,
|
||||
has_photos: photos.size.positive?,
|
||||
location: location,
|
||||
percentage_grown: percentage_grown.to_i,
|
||||
planted_at: planted_at,
|
||||
planted_from: planted_from,
|
||||
quantity: quantity,
|
||||
sunniness: sunniness,
|
||||
slug: slug,
|
||||
active: active,
|
||||
finished: finished?,
|
||||
has_photos: photos.size.positive?,
|
||||
location: location,
|
||||
percentage_grown: percentage_grown.to_i,
|
||||
planted_at: planted_at,
|
||||
planted_from: planted_from,
|
||||
planted_year: planted_at.year,
|
||||
quantity: quantity,
|
||||
sunniness: sunniness,
|
||||
garden_id: garden_id,
|
||||
|
||||
first_harvest_predicted_at: first_harvest_predicted_at,
|
||||
finish_predicted_at: finish_predicted_at,
|
||||
|
||||
# crops
|
||||
crop_id: crop_id,
|
||||
crop_name: crop.name,
|
||||
crop_slug: crop.slug,
|
||||
crop_id: crop_id,
|
||||
crop_name: crop_name,
|
||||
crop_slug: crop_slug,
|
||||
crop_perennial: crop_perennial,
|
||||
|
||||
# owner
|
||||
owner_id: owner_id,
|
||||
owner_location: owner_location,
|
||||
owner_login_name: owner_login_name,
|
||||
owner_slug: owner_slug,
|
||||
owner_id: owner_id,
|
||||
owner_location: owner_location,
|
||||
owner_login_name: owner_login_name,
|
||||
owner_slug: owner_slug,
|
||||
|
||||
# photos
|
||||
thumbnail_url: default_photo&.thumbnail_url || crop.default_photo&.thumbnail_url,
|
||||
thumbnail_url: default_photo&.thumbnail_url || crop.default_photo&.thumbnail_url,
|
||||
# counts
|
||||
photos_count: photos.size,
|
||||
harvests_count: harvests_count,
|
||||
photos_count: photos.size,
|
||||
harvests_count: harvests_count,
|
||||
|
||||
# timestamps
|
||||
created_at: created_at.to_i
|
||||
created_at: created_at.to_i
|
||||
}
|
||||
end
|
||||
|
||||
def self.homepage_records(limit)
|
||||
search('*', limit: limit,
|
||||
where: {
|
||||
photos_count: { gt: 0 }
|
||||
},
|
||||
boost_by: [:created_at],
|
||||
load: false)
|
||||
records = []
|
||||
owners = []
|
||||
1..limit.times do
|
||||
where = {
|
||||
photos_count: { gt: 0 },
|
||||
owner_id: { not: owners }
|
||||
}
|
||||
one_record = search('*',
|
||||
limit: 1,
|
||||
where: where,
|
||||
boost_by: [:created_at],
|
||||
load: false).first
|
||||
return records if one_record.nil?
|
||||
|
||||
owners << one_record.owner_id
|
||||
records << one_record
|
||||
end
|
||||
records
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user