Skip to content

Optimize Projects sidebar performance

gitlab-qa-bot requested to merge github/fork/jirutka/sidebar-perf into master

Created by: jirutka

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.

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).

Note: I’ve run tests on my machine with MRI 1.9.3-p327 and all passed.

Merge request reports