Running multiple sites on the same Rails app

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 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

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

require ‘ancestry’ # uses ancestry gem for hierarchies

class Category < ActiveRecord::Base
has_permalink :name, :permalink
has_many :downloads

def to_s { |cat| }.join(" > ")


def set_site
@site = Site.first(:conditions => {:domain => request.domain})

do some other stuff like set up some site-wide titles, logos, etc.


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?



On May 5, 12:24pm, Avishai [email protected] wrote:

Download objects can appear in 1 or more sites.

So what are the queries that are slow and what do they / their explain
plan look like ?


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs