Brad Fitzpatrick (bradfitz) wrote in lj_dev,
Brad Fitzpatrick

One code path!

Today I learned mod_rewrite. Damn is it cool.

So, gone forever is the 404notfound.cgi method of handling /~user/ and requests. In fact, the whole second <virtualhost> in LJ's httpd.conf has been removed. There's now just one vhost, with a ServerAlias of *

Then, some fun with rewrite:

  RewriteEngine on
  RewriteRule ^/~([a-z0-9_]+)(/?.*)$ /users/$1$2 [L,PT,NS]

  RewriteCond %{REQUEST_URI} !\.bml
  RewriteRule ^/community/([a-z0-9_]+)(/?.*)$ /users/$1$2 [L,PT,NS]

  RewriteCond %{HTTP_HOST} ^([a-z0-9_\-]+)\.livejournal\.com$ [NC]
  RewriteCond %1 !^www$ [NC]
  RewriteRule ^(.+) %{HTTP_HOST}$1  [C]
  RewriteRule ^([a-z0-9_]+)\.livejournal\.com(.+)  /users/$1$2  [L,PT,NS]

  RewriteRule ^/confirm/([a-z0-9]+\.[a-z0-9]+) \$1 [L,R]


The cool part now is that we don't have to have 'x' number of 404notfound.cgi FastCGI processes running and 'y' /htdocs/users processes running, trying to balance the ratio of 'x' and 'y' processes to match the ratio of request types. Now everything is handled the same way, so we get better resource usage, and less wasted memory on unused processes running.

Best ---- there is now just one code path to process journal requests. There used to be a ton of duplicated code in 404notfound.cgi and users. All gone.

While I was at it, I cleaned up all the interfaces to the style system generation code since they haven't been touched in months. They're now consistent with the argument conventions used elsewhere on the site. Because the LJ libraries now do a ton of work that I used to do by hand everywhere in the style system, a lot of that code is deleted too.

In summary --- much cleanup today. Much deleted code. Hooray. Too tired to release source now (since I'll have to update the INSTALL directions too), but I'll make that my project for tomorrow. Dormando pointed out that my livejournal-data.sql in yesterday's release still had references in it, but the upgrade/no-lj-in-styles.sql upgrade file didn't. So it looks like I ran the release script before I even updated the main server's SQL for the styles. (Styles can now have constants of the form %%cons:siteroot%% and %%cons:img%%, so no and references are in the styles.)


  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded