Page MenuHomePhabricator

New Term related classes should not maintain DB connections as call properties
Closed, ResolvedPublic

Description

A pattern emerged in the new term storage related db classes that maintains DB connections as class properties.
This goes against current patterns, and means that a reference to the db connection may hang around for longer than expected and this may not be desirable.

The pattern that should be used is:

  • Inject a loadbalancer
  • Get a connection from the load balancer when needed (repeated calls will end up getting the same connection)
  • Let the connection naturally fall out of scope at the end of your method

A very crude code search for this pattern in wikibase is: https://codesearch.wmflabs.org/extensions/?q=%5C%24this-%3E.*%20%3D%20.*-%3EgetConnection&i=nope&files=&repos=Extension:Wikibase

Event Timeline

Change 576147 had a related patch set uploaded (by Addshore; owner: Addshore):
[mediawiki/extensions/Wikibase@master] Do not hold DB connections in class properties in new term store classes

https://gerrit.wikimedia.org/r/576147

Change 576147 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Do not hold DB connections in class properties in new term store classes

https://gerrit.wikimedia.org/r/576147