Skip to content

Commit 3a223f1

Browse files
committed
Merge branch 'with_id_check_optimizations'
2 parents e3ef41c + 37707aa commit 3a223f1

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ OpenConferenceWare stable releases and changes included, with latest at top:
77
- FIXED Event, added uniqueness validations to slug and title fields.
88
- Improved models, added cascade deletes to avoid leaving orphaned records after parents are deleted.
99
- Improved "README", described the various custom environmental variables that affect the application's behavior.
10+
- Improved performance of event loading code by checking identifiers rather than loading entire objects.
1011
- Added QueryTrace plugin, it shows where database queries are done. Set QUERYTRACE=1 environmental variable to use.
1112

1213
* v0.20100429

app/helpers/application_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def assigned_events
211211

212212
# Return array of non-child events assigned to this request.
213213
def assigned_nonchild_events
214-
return self.assigned_events.compact.uniq.reject(&:parent)
214+
return self.assigned_events.compact.uniq.reject(&:parent_id)
215215
end
216216

217217
# Return array of non-child events assigned to this request sorted by end-date.

app/models/event.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ def end_date
205205

206206
# Return the parent event or this Event.
207207
def parent_or_self
208-
return self.parent || self
208+
return self.parent_id ?
209+
self.parent :
210+
self
209211
end
210212
end

spec/helpers/application_helper_spec.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def assign_events(events)
2525

2626
describe "assigned_nonchild_events" do
2727
it "should return only nonchild events" do
28-
parent = mock_model(Event, :parent => nil)
29-
child = mock_model(Event, :parent => parent)
28+
parent = mock_model(Event, :parent => nil, :parent_id => nil)
29+
child = mock_model(Event, :parent => parent, :parent_id => parent.id)
3030

3131
assign_events [parent, child]
3232

@@ -36,9 +36,18 @@ def assign_events(events)
3636

3737
describe "assigned_nonchild_events_by_date" do
3838
it "should return only nonchild events sorted by date" do
39-
first = mock_model(Event, :parent => nil, :end_date => Time.parse('2001/1/1'))
40-
second = mock_model(Event, :parent => nil, :end_date => Time.parse('2002/2/2'))
41-
child = mock_model(Event, :parent => second, :end_date => Time.parse('2002/2/2'))
39+
first = mock_model(Event,
40+
:parent => nil,
41+
:parent_id => nil,
42+
:end_date => Time.parse('2001/1/1'))
43+
second = mock_model(Event,
44+
:parent => nil,
45+
:parent_id => nil,
46+
:end_date => Time.parse('2002/2/2'))
47+
child = mock_model(Event,
48+
:parent => second,
49+
:parent_id => second.id,
50+
:end_date => Time.parse('2002/2/2'))
4251

4352
assign_events [second, child, first]
4453

spec/models/event_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,20 @@
118118
Event.new(:start_date => Date.today).dates.should == []
119119
end
120120
end
121+
122+
describe "#parent_or_self" do
123+
it "should find a parent when there is one" do
124+
parent = Event.create!(:title => "Mommy!", :slug => "mommy", :deadline => Time.now, :open_text => "Open!", :closed_text => "Closed!")
125+
child = Event.create!(:title => "Baby!", :slug => "baby", :deadline => Time.now, :open_text => "Open!", :closed_text => "Closed!", :parent => parent)
126+
127+
child.parent_or_self.should == parent
128+
end
129+
130+
it "should find self when there's no parent" do
131+
event = Event.create!(:title => "Event!", :slug => "event", :deadline => Time.now, :open_text => "Open!", :closed_text => "Closed!")
132+
133+
event.parent_or_self.should == event
134+
end
135+
end
136+
121137
end

0 commit comments

Comments
 (0)