gitlabhq/gitlabhq — pull request #2451 by jirutka (2013-01-01 20:08:18+00:00)
Title: Optimize Projects sidebar performance

Projects on sidebar contains their last activity, i.e. creation date of the last event associated with the project. Performance issue with the current implementation is that it generates extra query for every project in sidebar and every time when user open the Dashboard page. I have about 30 projects in my sidebar so that means 30 hits to database just to get last activity date of projects.

```sql
SELECT "events".* FROM "events" WHERE "events"."project_id" = 7 AND (author_id IS NOT NULL) ORDER BY events.created_at DESC LIMIT 1
```

This patch eliminates these extra queries entirely and thus significantly reduces load time of sidebar with many projects. Instead of querying for the last event to read its `created_at`, we can just read project’s `updated_at` attribute which is _touched_ (i.e. updated) while any event that belongs to the project is saved (see http://goo.gl/X4mOJ for example).