Hi, I''m using caches_page for images being grabbed from the DB. I just realized it would be cool, since images don''t get changed much, to get all DB images cached. So no user has to wait a while before the image is grabbed from the DB and processed, and instead they get the image served from the filesystem. So, my idea is to write a ruby script that gets all the id''s of the images from the DB and connects to the webserver and asks for each image (and thus, every image gets cached). But how can I get the ids of all the images easily with external Ruby code? I could do it using DBI, but AR has spoiled me. Thanks, Joe
Joe Van Dyk wrote:> I''m using caches_page for images being grabbed from the DB. > > I just realized it would be cool, since images don''t get changed much, > to get all DB images cached. So no user has to wait a while before > the image is grabbed from the DB and processed, and instead they get > the image served from the filesystem. > > So, my idea is to write a ruby script that gets all the id''s of the > images from the DB and connects to the webserver and asks for each > image (and thus, every image gets cached). > > But how can I get the ids of all the images easily with external Ruby > code? I could do it using DBI, but AR has spoiled me.You can access your whole Rails environment[1] by simply loading up the environment.rb file, or you can just require ''active_record'' and your db config[2]. 1. http://wiki.rubyonrails.com/rails/show/Environments#script 2. http://wiki.rubyonrails.com/rails/show/HowToPopulateYourDbFromScript I''m just guessing here, but something like this might work: require ''net/http'' RAILS_ENV = ''production'' require File.dirname(__FILE__) + ''/. ./config/environment'' Net::HTTP.start("www.example.com", 80) do |http| for image in Image.find_all http.get("/media/#{image.id}") end end Good luck, -- Lee
On Apr 7, 2005 4:06 PM, Lee O''Mara <lee-O8glSrxzjJo@public.gmane.org> wrote:> Joe Van Dyk wrote: > > I''m using caches_page for images being grabbed from the DB. > > > > I just realized it would be cool, since images don''t get changed much, > > to get all DB images cached. So no user has to wait a while before > > the image is grabbed from the DB and processed, and instead they get > > the image served from the filesystem. > > > > So, my idea is to write a ruby script that gets all the id''s of the > > images from the DB and connects to the webserver and asks for each > > image (and thus, every image gets cached). > > > > But how can I get the ids of all the images easily with external Ruby > > code? I could do it using DBI, but AR has spoiled me. > > You can access your whole Rails environment[1] by simply loading up the > environment.rb file, or you can just require ''active_record'' and your db > config[2]. > > 1. http://wiki.rubyonrails.com/rails/show/Environments#script > 2. http://wiki.rubyonrails.com/rails/show/HowToPopulateYourDbFromScript > > I''m just guessing here, but something like this might work: > > require ''net/http'' > > RAILS_ENV = ''production'' > require File.dirname(__FILE__) + ''/. ./config/environment'' > > Net::HTTP.start("www.example.com", 80) do |http| > for image in Image.find_all > http.get("/media/#{image.id}") > end > end > > Good luck, >Thanks! I was thinking along those lines but wasn''t sure what would be necessary to set the environment up.
On Apr 7, 2005 4:15 PM, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''m using caches_page for images being grabbed from the DB. > > I just realized it would be cool, since images don''t get changed much, > to get all DB images cached. So no user has to wait a while before > the image is grabbed from the DB and processed, and instead they get > the image served from the filesystem. > > So, my idea is to write a ruby script that gets all the id''s of the > images from the DB and connects to the webserver and asks for each > image (and thus, every image gets cached). > > But how can I get the ids of all the images easily with external Ruby > code? I could do it using DBI, but AR has spoiled me. >Look at script/console. I believe that all you need to do is include config/environment.rb. It should all be in script/console however. -- rick http://techno-weenie.net