Hi everyone,

So I have this app that I built which originally only needed to
support one site, and it runs quite fast. Now I added the ability to
run multiple sites on the same app, similar to how wordpress.com and
Posterous run multiple different sites with different domains and
content on the same software. However, since adding a Site model and
it's associations, the app is much, much slower. Using EXPLAIN I can
see that the additional JOINs are causing bottlenecks, and I'm having
trouble figuring out what the best indexing and lookup strategy is.
Download objects can appear in 1 or more sites.

The models go like this:

class Site < ActiveRecord::Base
  has_and_belongs_to_many :downloads
end

class Download < ActiveRecord::Base
  acts_as_taggable
  has_permalink :title
  belongs_to  :category
  has_and_belongs_to_many  :sites
end

require 'ancestry' # uses ancestry gem for hierarchies
https://github.com/stefankroes/ancestry
class Category < ActiveRecord::Base
  has_permalink :name, :permalink
  has_ancestry
  has_many  :downloads

  def to_s
    path.map { |cat| cat.name }.join(" > ")
  end
end

# application_controller.rb
def set_site
  @site = Site.first(:conditions => {:domain => request.domain})
  # do some other stuff like set up some site-wide titles, logos, etc.
end

Also, I want to be able to show only the categories that contain
active download objects for a particular site.

Can anyone help me figure out what the best way to go about this is?

Thanks!

Avishai

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to