views:

11

answers:

1

I'm using the instructions in this github readme file (at the bottom) to make ajax calls for autocompleting a list of tags, sort of like what this website does, actually!

It works pretty well, but it seems like it might be a little inefficient, since the list of tags almost never changes. Does anyone have recommendations on how to make this better? Like, if I could store a copy of the list of tags in memory somewhere, and just query that copy instead of querying the db?

@tags = Tag.restrict_taggable_type("Document").find(:all, :conditions => ["name LIKE ?", "%#{params[:tag]}%"])

Thanks...

+1  A: 
@tags ||= Tag.restrict_taggable_type("Document").find(:all, :conditions => ["name LIKE ?", "%#{params[:tag]}%"])

Huh?

floatless
heh, okay. and then i just set that again whenever the set of tags gets modified, huh?
unsorted
Yes. Invalidate it, for instance, every minute, every 60th request, or use an additional query to check for database changes (i.e. by counting tags).
floatless