mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-21 22:44:23 -04:00
Changed interesting methods to always return 12
... because it makes the caching more effective. Use .first(n) to get a smaller number if you want it.
This commit is contained in:
1 parent
5d3a44ae0c
commit
e8cb5e89b6
7 files changed
+14
-53
No files matched your search
@@ -8,11 +8,11 @@ class HomeController < ApplicationController
|
||||
@planting_count = Planting.count
|
||||
@garden_count = Garden.count
|
||||
|
||||
@crops = Crop.interesting(6)
|
||||
@crops = Crop.interesting.first(6)
|
||||
@recent_crops = Crop.recent.limit(12)
|
||||
@plantings = Planting.interesting(4)
|
||||
@seeds = Seed.interesting(6)
|
||||
@members = Member.interesting(6)
|
||||
@plantings = Planting.interesting.first(4)
|
||||
@seeds = Seed.interesting.first(6)
|
||||
@members = Member.interesting.first(6)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.haml
|
||||
|
||||
+3
-2
@@ -78,9 +78,10 @@ class Crop < ActiveRecord::Base
|
||||
return planted_from
|
||||
end
|
||||
|
||||
# Crop.interesting(howmany)
|
||||
# Crop.interesting
|
||||
# returns a list of interesting crops, for use on the homepage etc
|
||||
def Crop.interesting(howmany=12)
|
||||
def Crop.interesting
|
||||
howmany = 12 # max number to find
|
||||
interesting_crops = Array.new
|
||||
min_plantings = 3 # needs this many plantings to be interesting
|
||||
min_photos = 3 # needs this many photos to be interesting
|
||||
|
||||
@@ -181,7 +181,8 @@ class Member < ActiveRecord::Base
|
||||
return sets
|
||||
end
|
||||
|
||||
def Member.interesting(howmany=12)
|
||||
def Member.interesting
|
||||
howmany = 12 # max number to find
|
||||
interesting_members = Array.new
|
||||
Member.confirmed.located.recently_signed_in.each do |m|
|
||||
break if interesting_members.length == howmany
|
||||
|
||||
@@ -70,7 +70,8 @@ class Planting < ActiveRecord::Base
|
||||
# return a list of interesting plantings, for the homepage etc.
|
||||
# we can't do this via a scope (as far as we know) so sadly we have to
|
||||
# do it this way.
|
||||
def Planting.interesting(howmany=10)
|
||||
def Planting.interesting
|
||||
howmany = 12 # max amount to collect
|
||||
interesting_plantings = Array.new
|
||||
seen_owners = Hash.new(false) # keep track of which owners we've seen already
|
||||
|
||||
|
||||
+3
-2
@@ -30,9 +30,10 @@ class Seed < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
# Seed.interesting(howmany)
|
||||
# Seed.interesting
|
||||
# returns a list of interesting seeds, for use on the homepage etc
|
||||
def Seed.interesting(howmany=8)
|
||||
def Seed.interesting
|
||||
howmany = 12 # max number to find
|
||||
interesting_seeds = Array.new
|
||||
|
||||
Seed.tradable.each do |s|
|
||||
|
||||
@@ -221,31 +221,6 @@ describe Crop do
|
||||
Crop.interesting.length.should == 1
|
||||
end
|
||||
|
||||
it 'only gives you as many as you ask for' do
|
||||
# first, a couple of candidate crops
|
||||
@crop1 = FactoryGirl.create(:crop, :system_name => 'aaa')
|
||||
@crop2 = FactoryGirl.create(:crop, :system_name => 'zzz')
|
||||
|
||||
# they need 3+ plantings each to be interesting
|
||||
(1..3).each do
|
||||
FactoryGirl.create(:planting, :crop => @crop1)
|
||||
end
|
||||
(1..3).each do
|
||||
FactoryGirl.create(:planting, :crop => @crop2)
|
||||
end
|
||||
|
||||
# crops need 3+ photos to be interesting
|
||||
@photo = FactoryGirl.create(:photo)
|
||||
[@crop1, @crop2].each do |c|
|
||||
(1..3).each do
|
||||
c.plantings.first.photos << @photo
|
||||
c.plantings.first.save
|
||||
end
|
||||
end
|
||||
|
||||
Crop.interesting(1).length.should == 1
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -204,24 +204,6 @@ describe Planting do
|
||||
Planting.interesting.should_not include @planting1
|
||||
end
|
||||
|
||||
it 'only gives you as many as you ask for' do
|
||||
# plantings have members created implicitly for them
|
||||
# each member is different, hence these are all interesting
|
||||
@planting1 = FactoryGirl.create(:planting, :created_at => 5.days.ago)
|
||||
@planting2 = FactoryGirl.create(:planting, :created_at => 4.days.ago)
|
||||
@planting3 = FactoryGirl.create(:planting, :created_at => 3.days.ago)
|
||||
@planting4 = FactoryGirl.create(:planting, :created_at => 2.days.ago)
|
||||
|
||||
# plantings need photos to be interesting
|
||||
@photo = FactoryGirl.create(:photo)
|
||||
[@planting1, @planting2, @planting3, @planting4].each do |p|
|
||||
p.photos << @photo
|
||||
p.save
|
||||
end
|
||||
|
||||
Planting.interesting(2).length.should == 2
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user