This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db_config = YAML::load(File.read(RAILS_ROOT + "/config/database.yml")) | |
if db_config[Rails.env] | |
mongo = db_config[Rails.env] | |
mongo_host = mongo['host'] || 'localhost' | |
mongo_port = mongo['port'] || 27017 | |
RAILS_DEFAULT_LOGGER.error("Connecting to #{mongo_host}:#{mongo_port}") | |
MongoMapper.connection = Mongo::Connection.new(mongo_host, mongo_port, :logger => RAILS_DEFAULT_LOGGER) | |
MongoMapper.database = File.basename(mongo['database']).split(".")[0] | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@collection = db.collection('docs') | |
loop do | |
# Find a record to work on | |
new_record = @collection.find_one({:state => "NEW"}, {:sort => "created_at asc"}) | |
# Set the state to my process id, but only if it's still in the "NEW" state | |
response = @collection.update({:_id => new_record.id, :state => "NEW"}, | |
{'$set' => {:state => Process.pid}}, | |
{:upsert => false, :safe => true}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> db.users.find({last_logged_in : {'$gt': new Date(0)}}).explain() | |
{ | |
"cursor" : "BtreeCursor last_logged_in_1", | |
"startKey" : { | |
"last_logged_in" : "Wed Dec 31 1969 16:00:00 GMT-0800 (PST)" | |
}, | |
"endKey" : { | |
"last_logged_in" : "Tue Jan -2147483647 584556020 06:25:52 GMT-0800 (PST)" | |
}, | |
"nscanned" : 8, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> db.users.find({last_logged_in : {'$gt': 0}}).explain() | |
{ | |
"cursor" : "BtreeCursor last_logged_in_1", | |
"startKey" : { | |
"last_logged_in" : 0 | |
}, | |
"endKey" : { | |
"last_logged_in" : 1.7976931348623157e+308 | |
}, | |
"nscanned" : 0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> db.users.find({last_logged_in : {'$gt': null}}).explain() | |
{ | |
"cursor" : "BtreeCursor last_logged_in_1", | |
"startKey" : { | |
"last_logged_in" : null | |
}, | |
"endKey" : { | |
"last_logged_in" : { | |
"$maxElement" : 1 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> db.users.find({last_logged_in : {'$ne': null}}).hint({last_logged_in: 1}).explain() | |
{ | |
"cursor" : "BtreeCursor last_logged_in_1", | |
"startKey" : { | |
"last_logged_in" : { | |
"$minElement" : 1 | |
} | |
}, | |
"endKey" : { | |
"last_logged_in" : { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> db.users.find({last_logged_in : {'$ne': null}}).explain() | |
{ | |
"cursor" : "BasicCursor", | |
"startKey" : { | |
}, | |
"endKey" : { | |
}, | |
"nscanned" : 536299, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note that I have Rails 2.3.4 installed on this machine already. | |
[12] <ci> [01:17 PM] /opt/app>sudo gem install awesome_nested_set | |
Successfully installed activesupport-2.3.5 | |
Successfully installed activerecord-2.3.5 | |
Successfully installed awesome_nested_set-1.4.3 | |
3 gems installed | |
Installing ri documentation for activesupport-2.3.5... | |
Installing ri documentation for activerecord-2.3.5... | |
Installing ri documentation for awesome_nested_set-1.4.3... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for repo in * | |
do | |
[ ! -d $repo ] && continue | |
[ ! -d $repo/.git ] && continue | |
cd $repo; | |
echo $repo; | |
git pull; | |
cd - > /dev/null | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> class Session < ActiveRecord::Base; end # So we can access the sessions table directly | |
=> nil | |
>> s = Session.first | |
=> #<Session id: 1, session_id: "bd0568033d143fafaa1f9752c43b61d7", data: "BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g...", created_at: "2008-12-10 15:50:58", updated_at: "2008-12-10 17:50:47"> | |
>> session_data = Marshal.load(Base64::decode64(s.data)) | |
=> {"flash" => {}} | |
>> Rails.cache.write("rack:session:#{s.session_id}", session_data) | |
=> true |