Simply viewing an article currently involves performing a lot of queries. Since it's our most common event, we should perhaps be directing optimizing effort in that direction.
(if logged in) check user info: User::loadFromDatabase:SQL: SELECT user_name,user_password, user_newpassword,user_email,user_options,user_rights,user_newtalk FROM user WHERE user_id=1
Check if page exists: LinkCache::addLink:SQL: SELECT cur_id FROM cur WHERE (cur_namespace=0 AND cur_title='Test:stuff')
Load the content: Article::loadContent:SQL: SELECT cur_text,cur_timestamp,cur_user, cur_counter FROM cur WHERE cur_id=19
[These last two can be combined into one query.]
Now, separately for each and every linked page: Check if it exists: LinkCache::addLink:SQL: SELECT cur_id FROM cur WHERE (cur_namespace=0 AND cur_title='A_link')
(if stub threshold set) check its size and redirect status: SQL: SELECT length(cur_text) AS x, cur_namespace, cur_is_redirect FROM cur WHERE cur_id='96'
[Checking the size can be done with checking existence, and it may be better to chalk up a list of all linked pages during initial parsing, then check them all in one big query.]
Check if current page is restricted for editing: wfGetSQL:SQL: SELECT cur_restrictions FROM cur WHERE (cur_id=19)
[We should get cur_restrictions along with the rest in the initial query.]
(if logged in) check if on watchlist: wfGetSQL:SQL: SELECT user_watch FROM user WHERE (user_id=1)
[For users with big watchlists like me, it may be inefficient to load and parse the entire list on every single page view. It should perhaps either be grabbed along with the rest of the user info, or stored in a separate table where the database can parse the gobs of strings for us.]
Check for existence of talk page (twice - sidebar and bottom bar): LinkCache::addLink:SQL: SELECT cur_id FROM cur WHERE (cur_namespace=1 AND cur_title='Test:stuff') LinkCache::addLink:SQL: SELECT cur_id FROM cur WHERE (cur_namespace=1 AND cur_title='Test:stuff')
[Should only need to do this once and store the result...]
...output the page...
Update counters: ViewCountUpdate::doUpdate:SQL: UPDATE cur SET cur_counter=(1+cur_counter),cur_timestamp=cur_timestamp WHERE cur_id=19 SiteStatsUpdate::doUpdate:SQL: UPDATE site_stats SET ss_total_views=(ss_total_views+1), ss_total_edits=(ss_total_edits), ss_good_articles=(ss_good_articles) WHERE ss_row_id=1
[Note that that single row of site_stats is updated on every single view of any page in the database.]
-- brion vibber (brion @ pobox.com)
wikitech-l@lists.wikimedia.org