Skip to content

Commit

Permalink
Remove CacheLookupsMixin
Browse files Browse the repository at this point in the history
We've seen some issues with cached lookups failing to return records
when running in production.

Refs #65
  • Loading branch information
reidab committed Dec 16, 2013
1 parent 7bec873 commit 2713fce
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 284 deletions.
Expand Up @@ -242,7 +242,7 @@ def log_the_session

# Assign an @events variable for use by the layout when displaying available events.
def assign_events
@events = Event.lookup
@events = Event.all
end

# Return the event and a status which describes how the event was assigned. The status can be one of the following:
Expand All @@ -257,7 +257,7 @@ def get_current_event_and_assignment_status
# Try finding event using params:
event_id_key = controller_name == "events" ? :id : :event_id
if key = params[event_id_key]
if event = Event.lookup(key)
if event = Event.find(key)
return [event, :assigned_to_param]
else
logger.info "error, couldn't find event from key: #{key}"
Expand Down
Expand Up @@ -11,7 +11,7 @@ class EventsController < ApplicationController
# GET /events
# GET /events.xml
def index
@events = Event.lookup
@events = Event.all

respond_to do |format|
format.html # index.html.erb
Expand Down Expand Up @@ -108,7 +108,7 @@ def notify_speakers
already_emailed = []
proposals = params[:proposal_ids].split(',')
proposals.each do |proposal_id|
proposal = Proposal.lookup(proposal_id)
proposal = Proposal.find(proposal_id) rescue nil
next unless proposal
case params[:proposal_status]
when 'accepted'
Expand Down
Expand Up @@ -393,7 +393,7 @@ def assert_anonymous_proposals
# * :invalid_proposal
# * :invalid_event
def get_proposal_and_assignment_status
if proposal = Proposal.lookup(params[:id].to_i) rescue nil
if proposal = Proposal.find(params[:id].to_i) rescue nil
if proposal.event
return [proposal, :assigned_via_param]
else
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/open_conference_ware/snippets_helper.rb
Expand Up @@ -4,7 +4,7 @@ module SnippetsHelper
# Return the Snippet record matching the +slug+, else raise a
# ActiveRecord::RecordNotFound.
def snippet_record_for(slug)
if record = Snippet.lookup(slug.to_s)
if record = Snippet.find_by_slug(slug.to_s)
return record
else
raise ActiveRecord::RecordNotFound, "Can't find snippet: #{slug}"
Expand Down
128 changes: 0 additions & 128 deletions app/mixins/open_conference_ware/cache_lookups_mixin.rb

This file was deleted.

9 changes: 1 addition & 8 deletions app/models/open_conference_ware/event.rb
Expand Up @@ -27,12 +27,8 @@ module OpenConferenceWare

class Event < OpenConferenceWare::Base
# Mixins
### Provide cached Snippet.lookup(id) method.
include CacheLookupsMixin
include SimpleSlugMixin

cache_lookups_for :slug, order: 'deadline desc', include: [:tracks, :rooms]

# Associations
has_many :proposals, dependent: :destroy
has_many :tracks, dependent: :destroy
Expand Down Expand Up @@ -86,10 +82,7 @@ def current?
# see if a snippet says which is current, else tries to return the event
# with the latest deadline, else returns a nil.
def self.current
query = lambda {|*args| self.current_by_settings || self.current_by_deadline }
return self.cache_lookups? ?
self.fetch_object('event_current', &query) :
query.call
self.current_by_settings || self.current_by_deadline
end

# Return current event by finding it by deadline.
Expand Down
6 changes: 0 additions & 6 deletions app/models/open_conference_ware/proposal.rb
Expand Up @@ -38,9 +38,6 @@ class Proposal < OpenConferenceWare::Base
# Provide ::event_tracks? and other methods for accessing SETTING
include SettingsCheckersMixin

# Provide ::lookup
include CacheLookupsMixin

# Provide ::overlaps?
include ScheduleOverlapsMixin

Expand All @@ -57,9 +54,6 @@ class Proposal < OpenConferenceWare::Base
:track_id, :track_title,
:user_ids, :user_titles


cache_lookups_for :id, order: 'submitted_at desc', include: [:event, :track, :room, :users]

# Provide #tags
acts_as_taggable_on :tags

Expand Down
7 changes: 1 addition & 6 deletions app/models/open_conference_ware/snippet.rb
Expand Up @@ -15,11 +15,6 @@ module OpenConferenceWare
#

class Snippet < OpenConferenceWare::Base

# Provide cached Snippet.lookup(slug) method.
include CacheLookupsMixin
cache_lookups_for :slug, order: :slug

# Load the Snippets as defined in the "spec/fixtures/snippets.yml" file and
# load them into the current database, overwriting any existing records.
def self.load_from_fixtures(overwrite = false)
Expand All @@ -43,7 +38,7 @@ def self.reload_from_fixtures!

# Returns the content for a Snippet match +slug+, else raise an ActiveRecord::RecordNotFound.
def self.content_for(slug)
if record = self.lookup(slug.to_s)
if record = self.find_by_slug(slug.to_s)
return record.content
else
raise ActiveRecord::RecordNotFound, "Couldn't find snippet: #{slug}"
Expand Down
Expand Up @@ -362,7 +362,7 @@ def get_entry(proposal_symbol)
it "should redirect back to proposals list if asked to display a proposal without an event" do
proposal = proposals(:quentin_widgets)
proposal.stub(event: nil)
Proposal.stub(find_by_id: proposal, find: proposal, lookup: proposal)
Proposal.stub(find_by_id: proposal, find: proposal)

get :show, id: proposal.id

Expand Down Expand Up @@ -449,7 +449,7 @@ def assert_show(opts={}, &block)
old_session = stub_model(Proposal, status: 'confirmed', event: old_event)
old_session.users << old_session_user

Proposal.stub(find: old_session, find_by_id: old_session, lookup: old_session)
Proposal.stub(find: old_session, find_by_id: old_session)
Event.stub(current: current_event)

get :session_show, id: old_session.id
Expand Down Expand Up @@ -478,7 +478,7 @@ def assert_show(opts={}, &block)
it "should not notify owners of acceptance if proposal confirmation controls are not visible" do
event = @proposal.event
event.stub(:show_proposal_confirmation_controls? => false)
Proposal.stub(lookup: @proposal)
Proposal.stub(find: @proposal)

login_as(users(:quentin))

Expand Down Expand Up @@ -951,7 +951,7 @@ def assert_update(login=nil, inputs={}, optional_params={}, &block)
describe "delete" do
before do
@proposal = proposals(:quentin_widgets)
Proposal.stub(:lookup).and_return(@proposal)
Proposal.stub(:find).and_return(@proposal)
end

def assert_delete(login=nil, &block)
Expand Down Expand Up @@ -1238,7 +1238,7 @@ def assert_not_declined

it "should return a status of :invalid_event when a proposal doesn't have a valid event" do
proposal = stub_model(Proposal, state: "confirmed", event: nil)
Proposal.stub(:lookup).and_return(proposal)
Proposal.stub(:find).and_return(proposal)
@controller.stub(:params).and_return({ id: 1000 })
@controller.send(:get_proposal_and_assignment_status).should == [proposal, :invalid_event]
end
Expand Down

0 comments on commit 2713fce

Please sign in to comment.