A Django site.
March 27, 2008

Hans Fugal
no nic
The Fugue :
» Rails Sessions

I was doing some maintenance on my blog, and was devastated to find that Typo was taking 225 megabytes of resident RAM. Yikes! After some creative debug thinking and digging I figured out it was due to sessions. Typo now stores sessions in the database, so my maintenance cron job to delete old sessions didn't clean up old sessions. (Ha! had you going for a second!)

Well I could write a cron job to run a script to clean the sessions out of the db, like:

#!/bin/sh
sqlite3 /path/to/typo/db/production.db 'delete from sessions'

Ok, that's a bit extreme, but you get the idea. But when I deleted the sessions in this manner the memory usage didn't drop at all until I had restarted the server, which seems unnecessary. So instead I changed typo's configuration to use a different session store. I commented out this line in config/environment.rb:

-  config.action_controller.session_store = :active_record_store
+  #config.action_controller.session_store = :active_record_store

Then I restarted the server and fired up a browser. "Huh, that's odd… no sessions in tmp/sessions or /tmp or anywhere I can see. No, they're not in the database…" What I was seeing didn't match up with what all the stuff Google said. The default session store was PStore, aka file system, so they said. But apparently that recently changed in Rails, and now the default is CookieStore. From ActionController::Base documentation:

Sessions are stored in a browser cookie that‘s cryptographically signed, but unencrypted, by default. This prevents the user from tampering with the session but also allows him to see its contents.

Do not put secret information in session!

Well a quick grep -ri session app lib told me that typo wasn't storing anything secret, so I decided that default was alright with me. Now I don't have to set up any session cleanup script at all. Sweet.

Now, don't stop there. You should set your session key and secret while you're hanging out in config/environment.rb. Add the following lines in the same place as the line you commented out above:

config.action_controller.session['session_key'] = 'something unique'
config.action_controller.session['secret'] = 'get this from rake secret'

October 29, 2007

Hans Fugal
no nic
The Fugue :
» Typo and the Amazon Sidebar

I finally got the typo amazon sidebar working. Nifty thumbnails and riches beyond measure are now mine! Well, at least the thumbnails…

This is what you need to do. Enable the Amazon postprocessor in your preferred text filter (e.g. Markdown), which lets you write urls as <a href="amazon:0743253434">…</a>. (Note: I find that if you don't use double quotes it doesn't work) Then, set up the Amazon sidebar, which is straightforward. Handcrafted URLs don't seem to work, though it's possible a handcrafted URL of the kind generated by the Amazon filter would (e.g. http://www.amazon.com/exec/obidos/ASIN/0743253434/thefug-20).

October 28, 2007

Hans Fugal
no nic
The Fugue :
» Typo with a Prefix

I just set up Typo again, for my wife's blog. She wanted the url http://erin.fugal.net/blog, the important part here is the /blog bit at the end. Rails in general has traditionally been fairly hostile to this prefix thing, but Typo has smoothed things out considerably. I've blogged about this before, but typo has changed in the meantime. Here's what you do:

First, in your Apache2 config change the ProxyPass and ProxyPassReverse lines to have /blog in both places, e.g.

ProxyPass             /blog http://localhost:4907/blog
ProxyPassReverse      /blog http://localhost:4907/blog

Then, tell typo about it:

cd /path/to/my/typo
typo config . prefix-url=/blog
typo restart .

Finally, you may need to flush the cache and/or reactivate the theme of your choice.

Kudos to the typo folks for making this relatively painless. Getting it to work in the "good ol' days" was truly painful.

October 27, 2007

Hans Fugal
no nic
The Fugue :
» Typo Cache

Typo, the blogging software that runs this blog, was getting slower and slower for an unknown reason. Finally I decided I had had enough and begged for help in IRC. sprewell was kind enough to help me track it down to an odd caching problem. Apparently my caches weren't going away like they should, and I had accumulated some 1.7 million files in my tmp/cache directory. Even running find tmp/cache | wc -l took a few minutes. No wonder typo (which was probably actually looking at each file's contents) was having a cow. Apparently this isn't a common problem, but they have struggled with cache problems in the past. So if your typo is feeling sluggish, check for the ballooning cache. If it's there, stop typo and move or delete the offending cache directory, i.e.

typo stop .
mv tmp/cache /tmp
typo start .

It's nice to have my old typo back.