Skip to content

Commit

Permalink
Added a end user caches table. Used to store a full text index on all
Browse files Browse the repository at this point in the history
the end user fields.
  • Loading branch information
Doug Youch committed May 24, 2010
1 parent b65b131 commit 3b8e6eb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/models/end_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ class EndUser < DomainModel
has_many :addresses, :class_name => 'EndUserAddress', :dependent => :destroy

has_one :tag_cache, :dependent => :destroy

has_one :end_user_cache, :dependent => :destroy, :class_name => 'EndUserCache'

has_many :end_user_cookies, :dependent => :delete_all, :class_name => 'EndUserCookie'

has_many :end_user_actions, :dependent => :delete_all
Expand Down Expand Up @@ -128,6 +129,10 @@ def after_create #:nodoc:
end
end

def after_save #:nodoc:
self.end_user_cache ? self.end_user_cache.save : EndUserCache.create(:end_user_id => self.id)
end

## Validation Fucntions


Expand Down
25 changes: 25 additions & 0 deletions app/models/end_user_cache.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

class EndUserCache < DomainModel
belongs_to :end_user
validates_presence_of :end_user_id

def before_save
self.data = self.get_end_user_data.delete_if { |v| v.blank? }.join(' ')
end

def get_end_user_data
data = [
self.end_user.email,
self.end_user.name,
self.end_user.user_class.name,
self.end_user.source,
self.end_user.registered? ? 'registered' : nil
]
end

def self.reindex
EndUser.find_in_batches do |users|
users.each { |user| user.save }
end
end
end
9 changes: 9 additions & 0 deletions db/migrate/20100511165552_user_segments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,20 @@ def self.up
end

add_index :user_segment_analytics, [:user_segment_id], :name => 'user_segment_analytics_segment_idx'

create_table :end_user_caches, :force => true, :options => "ENGINE=MyISAM" do |t|
t.integer :end_user_id
t.text :data
end

add_index :end_user_caches, [:end_user_id], :name => 'end_user_caches_idx', :unique => true
execute "CREATE FULLTEXT INDEX end_user_caches_data_index ON end_user_caches (data)"
end

def self.down
drop_table :user_segments
drop_table :user_segment_caches
drop_table :user_segment_analytics
drop_table :end_user_caches
end
end

0 comments on commit 3b8e6eb

Please sign in to comment.