jgubman / masochism Goto Github PK
View Code? Open in Web Editor NEWThis project forked from technoweenie/masochism
ActiveRecord connection proxy for master/slave connections
License: MIT License
This project forked from technoweenie/masochism
ActiveRecord connection proxy for master/slave connections
License: MIT License
masochism ============== The masochism plugin provides an easy solution for Ruby on Rails applications to work in a replicated database environment. Connection proxy sends some database queries (those in a transaction, update statements, and ActiveRecord::Base#reload) to a master database, and the rest to the slave database. The ActiveReload::MasterDatabase model uses a 'master_database' setting in database.yml to serve as the master database. # config/database.yml login: &login adapter: postgresql host: localhost port: 5432 production: database: slave_database_name <<: *login master_database: database: master_database_name <<: *login To setup: Whether you want this in production only, or maybe just your deployment server, is up to you. Just call the following method in your desired environment file. ActiveReload::ConnectionProxy.setup! Some suggestions: * in a config/initializer * config.after_initialize block If you are using the Litespeed web server, child processes are initialized on creation, which means any setup done in an environment file will be effectively ignored. A brief discussion of the problem is posted here: http://litespeedtech.com/support/wiki/doku.php?id=litespeed_wiki:rails:memcache One solution for Litespeed users is to check the connection at your first request and do the setup! call if your connection hasn't been initialized, like: class ApplicationController < ActionController::Base prepend_before_filter do |controller| ActiveReload::ConnectionProxy.setup! unless ActiveRecord::Base.connection.is_a? ActiveReload::ConnectionProxy end ... end If you want a model to always use the Master database, you can inherit ActiveRelaod::MasterDatabase. Any models with their own database connection will not be affected. Setting up your own proxies: # Sets up MyMaster's connection as the master database connection for User. ActiveReload::ConnectionProxy.setup_for MyMaster, User
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.