Page MenuHomePhabricator

Lua: Make it possible to load all statements for only one property of an entity using mw.wikibase
Closed, ResolvedPublic

Description

The work done T172905 resulted in the availability of the mw.wikibase.getBestStatements function that helps makes tracking Wikidata more efficient. At rowiki, this has helped us drastically reduce the tracking of entire entities and made queries more efficient.

We could still do more; especially if we had some function that doesn't limit itself to just the "best" statements for an entity. We have some use cases that might benefit from that.

One example is our HistoricalCountries module which lists all the countries in which a city (or anything for that matter) was throughout history. In this case, P17 (country) for the entity will have one 'preferred' statement (with the current country), as well as more 'normal' statements, with P580 and P582 qualifiers for the historic ones. We also do a lot more magic with these 'normal' statements hidden beneath one or more 'preferred' ones: we extract the country and official name of a town for a specific date in time - for instance, to show that when Max Born was born (pun not intended) in 1882, he was born in Breslau, German Empire, not Wrocław, Poland (as it is today). We do similar stuff with flags for countries that changed their flag throughout their existence.

So, we still have a lot of code that loads an entire entity just to cycle through the claims associated with only one property, and the usage tracking of these entities could be helped a lot by something similar to mw.wikibase.getBestStatements, only with the 'best' part left out.

Event Timeline

Makes sense to me.

Change 381028 had a related patch set uploaded (by Hoo man; owner: Hoo man):
[mediawiki/extensions/Wikibase@master] Lua: Add mw.wikibase.getStatements

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

My proposed implementation includes "deprecated" statements as well, I guess this ok here?

Yes, it's perfectly OK, because the code I'm going to replace with a call to this function is brutely iterating through the claims table.
Further filtering should be left to the calling module.

Change 376838 had a related patch set uploaded (by Thiemo Mättig (WMDE); owner: Thiemo Mättig (WMDE)):
[mediawiki/extensions/Wikibase@master] [WIP] Add a mw.wikibase.getAllStatements Lua function

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

Change 381028 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Lua: Add mw.wikibase.getStatements

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

Change 376838 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Update documentation of getBestStatements/getAllStatements in Lua

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

hoo moved this task from Review to Done on the Wikidata-Former-Sprint-Board board.
hoo removed a project: Patch-For-Review.