zen of coding

  • http://www.jblotus.com James Fuller

    Great tip, a read only database is a good solution. On our site at work we try to use the read only slave in as many situations as possible. One time where you might not wish to use it though is with time-critical data. Occasionally the read only db will get backed up when it comes to replication. Also having a fallback to the master is probably a good idea.

  • http://josediazgonzalez.com Jose Gonzalez

    Would it not be more useful to have this as a behavior? You could automagically crawl the contains and conditions (to some default recursion level) to switch the datasource in the Behavior::beforeFind() and switch back in the Behavior::afterFind(). Of course you could provide an override for when the recursion isn’t useful enough, but it would be a nicer-looking implementation than this.

    Also, does this work for manually specified joins? Just curious.

  • teknoid

    @Jose Gonzalez

    1. I am pretty sure it does work with manual joins, but I need to look at the code of the app to be sure.
    2. This approach is a little safer than going full force with Behavior, because (in our case at least) all reads could not be offloaded to replica for the very reason James Fuller mentioned above (real-time data requirement). Plus it was much faster to implement in a short deadline … an hour, before DB blows up :)

%d bloggers like this: