Page MenuHomePhabricator

ShortUrl must not write to master db on page views (DBPerformance warning)
Open, MediumPublic

Description

This can be fixed by the UrlShortener migration I suppose.

Expectation (writes <= 0) by MediaWiki::main not met:
query-m: INSERT IGNORE INTO `shorturls` (su_id,su_namespace,su_title) VALUES (NULL,'X') [TRX#15eeb384bc89]
TransactionProfiler.php line 311 calls wfBacktrace()
TransactionProfiler.php line 200 calls TransactionProfiler->reportExpectationViolated()
Database.php line 1006 calls TransactionProfiler->recordQueryCompletion()
Database.php line 1935 calls DatabaseBase->query()
ShortUrl.utils.php line 54 calls DatabaseBase->insert()
ShortUrl.hooks.php line 44 calls ShortUrlUtils::encodeTitle()
Hooks.php line 195 calls ShortUrlHooks::addToolboxLink()
VectorTemplate.php line 319 calls Hooks::run()
VectorTemplate.php line 273 calls VectorTemplate->renderPortal()
VectorTemplate.php line 195 calls VectorTemplate->renderPortals()
SkinTemplate.php line 242 calls VectorTemplate->execute()
OutputPage.php line 2318 calls SkinTemplate->outputPage()
MediaWiki.php line 739 calls OutputPage->output()
MediaWiki.php line 506 calls MediaWiki->main()
index.php line 43 calls MediaWiki->run()
index.php line 3 calls include()

Event Timeline

aaron claimed this task.
aaron removed aaron as the assignee of this task.
aaron raised the priority of this task from to Medium.
aaron updated the task description. (Show Details)
aaron added a project: Performance Issue.
aaron set Security to None.
aaron added subscribers: Amire80, daniel, Johan and 11 others.

This particular DBPerformance error happens about once every minute from page views on wikis with ShortUrl installed.

For the record, this write is not deferred as update. Rather, it happens synchronously during the page view from a hook in the Vector skin because the interface wants to show the short url always, even if it hasn't been created yet. This is a logical restriction that can't be avoided in code unless the user interface is changed.

As such, we probably need to change the extension so that if there is no short url in the database for the current page, we must not show one. We should probably also create the short url automatically for newly created pages, from a hook during page creation, so that it will always exist for new pages. That should significantly reduce the changes of no url being shown, as I suspect that this is mostly happening in cases of a page being created and then immediately being viewed, which probably happens more often then someone viewing an older page that has never been viewed since the installation of the extension.

For the latter case, we can probably still lazily create the short url, but maybe from a deferred update or job, for the next visitor. In that case we need to think about how to handle the Varnish cache, as we probably won't want to wait a week for the next cache miss for the url to show up. I guess the job could purge the url in Varnish?

Krinkle renamed this task from Avoid ShortUrl master writes on page view to ShortUrl should not write to master db on page views (DBPerformance warning).Sep 18 2018, 8:54 PM
Jdforrester-WMF renamed this task from ShortUrl should not write to master db on page views (DBPerformance warning) to ShortUrl must not write to master db on page views (DBPerformance warning).Oct 11 2018, 10:38 PM

Can we just deprecate ShortUrl in favor of UrlShotener?

Can we just deprecate ShortUrl in favor of UrlShotener?

Discussion about this T187045.

mmodell changed the subtype of this task from "Task" to "Production Error".Aug 28 2019, 11:11 PM
Krinkle changed the subtype of this task from "Production Error" to "Task".