Rob Olson's blog
Ask for Help
Paperclip Slowness
"In one web request we are collecting the file paths of about 250 objects that have attachments via Paperclip. Unfortunately this is really slow and takes a couple seconds to finish. Does anyone have thoughts on how we could speed this up? Is de-normalizing the file path a reasonable solution?"
Moderation of Solr Search Results
"One of our projects uses Solr and acts_as_solr to provide search results to users. One particular result is showing up far higher than we want. What is the best way to use boosting to downgrade the score of an individual result in Solr?"
Interesting Things
Bike to Work Day
May 13th is Bike to Work Day in San Francisco. We are hoping more people take advantage of this to try biking to work for the first time. To mix things up for those that normally bike to work we are planning a Bike to Lunch.
Happy Star Wars Day!
Ask for Help
"While Apache is serving a large static file it becomes slow to serve other requests. We think this may be an Apache configuration issue. Any suggestions?"
Interesting Things
Enable-pthreads Headache
In Ruby 1.8 the --enable-pthreads build option will dramatically slow down your program, as documented here and here. Do not enable it unless you need it, which is unlikely.
Don't need a primary key? Think again
You might think that you can get away with not having a primary key on a table and just rely on a database index for lookups. This is very dangerous because MySQL will no longer be able to store the records on disk sorted by primary key. Not having this ordering becomes an issue if you want to operate on the records in batches. For instance, normally you ask for all the records having an id between 0 and 1000. Because they are stored by primary key these 1000 records will be in a group on the disk and the lookup will be quick. When doing the same thing with an index instead of a primary key, and a primary key does not exist, the records will be in scattered locations on the disk and the hard drive will have to do many seeks to access them all. The time to do query will be orders of magnitude greater.
Ask for Help
"We are attempting to upgrade one of our projects using Fixture Scenarios to Rails 2.3.2. When we attempt to run our tests we get errors about a corrupt fixture file. Is anyone successfully using Fixture Scenarios with Rails 2.3?"
Interesting Things
It is really easy to declare an additional route just for use in a controller test. All that is needed is to recall ActionController::Routing::Routes.draw at the top of your spec file. One situation in which this can be useful is if you are creating a new controller just for testing purposes.
class DummiesController < ApplicationController before_filter :require_profile def index end end ActionController::Routing::Routes.draw do |map| map.resources :dummies end describe DummiesController do ... end
Ask for Help
"When attempting to upload files with the aws-s3 gem I am receiving a lot of timeouts. This seems to happen with both small and large files. Has anyone run into this before?"
It was hypothesized that this could be the result of a slow internet connection and saturating the upload stream. Does anyone know of a fix for s3 timeouts?
Ask for Help
"Is there a good way to temporarily redefine a method on a controller during a functional test?"
Reopening a controller and overriding a method affects all tests in a suite. Is there a good way to redefine a controller method for a single test?
Interesting Things
- Rails 2.3.3 was released yesterday. It is a minor point release but a notable new feature is a faster decoding backend for JSON.
- The Evening with Palm webOS event is tonight at 6:30!
- There is a new mailing list for the Jasmine Javascript testing framework.
- Braid gotcha be careful when using Braid to checkout a specific branch of a Git repository. If you checkout a repository with Braid, and then later decide that you want to switch to a different branch (i.e. going from master to 2-3-stable with Rails) doing a
braid remove vendor/railsis not sufficient! The reason is when you add a external with Braid it also adds a remote branch in your Git repository. If you re-add the external, the old remote will be reused, even if you specify a different branch. To avoid this, remove the remote in addition to removing the external. To view your remotes rungit remoteand remove a remote withgit remove rm some/remote/name.
Weirdness with using serialized with Single Table Inheritance in Rails
If you have a class that uses a serialized categories attribute like this:
class Wibble < ActiveRecord::Base
serialized :categories
end
Interesting Things
Prior to RSpec 1.2.7, render_template in rspec-rails had a bug where render_template('new') would pass if 'newer' was rendered (or anything that started with 'new'). Internally render_template was converting the string argument to a regular expression which was allowing 'new' to positively match 'newer' even though it was not an exact match. In RSpec-Rails 1.2.7 this bug has been fixed.
