jenkins-bot has submitted this change and it was merged.
Change subject: Lua: Cache more stuff in memory
......................................................................
Lua: Cache more stuff in memory
Cache wikibase.entity objects and the entity id belonging to
the current page in memory, so that we don't have to get them
from PHP this often.
Change-Id: I22d4f9d2fd1f01a9bfffde77d6c9c75842e28d9e
---
M client/includes/scribunto/mw.wikibase.lua
1 file changed, 32 insertions(+), 16 deletions(-)
Approvals:
Aude: Looks good to me, approved
WikidataJenkins: Verified
jenkins-bot: Verified
diff --git a/client/includes/scribunto/mw.wikibase.lua
b/client/includes/scribunto/mw.wikibase.lua
index d72c1e9..4b904f3 100644
--- a/client/includes/scribunto/mw.wikibase.lua
+++ b/client/includes/scribunto/mw.wikibase.lua
@@ -15,21 +15,43 @@
local php = mw_interface
mw_interface = nil
- -- Caching variable for the wikibase.entity object belonging to the
current page
- local entity = false
+ -- Caching variable for the wikibase.entity objects
+ local entities = {}
+ -- Caching variable for the entity id string belonging to the current
page (nil if page is not linked to an entity)
+ local pageEntityId = false
+ -- Get the mw.wikibase.entity object for a given id. Cached.
local getEntityObject = function( id )
- local entity = php.getEntity( id, false )
- if type( entity ) ~= 'table' then
- return nil
+ if entities[ id ] == nil then
+ local entity = php.getEntity( id, false )
+
+ if type( entity ) ~= 'table' then
+ entities[ id ] = false
+ return nil
+ end
+
+ entities[ id ] = wikibase.entity.create( entity )
end
- return wikibase.entity.create( entity )
+ if type( entities[ id ] ) == 'table' then
+ return entities[ id ]
+ else
+ return nil
+ end
+ end
+
+ -- Get the entity id for the current page. Cached
+ local getEntityIdForCurrentPage = function()
+ if pageEntityId == false then
+ pageEntityId = php.getEntityId( tostring(
mw.title.getCurrentTitle().prefixedText ) )
+ end
+
+ return pageEntityId
end
-- @DEPRECATED, uses a legacy plain Lua table holding the entity
wikibase.getEntity = function()
- local id = php.getEntityId( tostring(
mw.title.getCurrentTitle().prefixedText ) )
+ local id = getEntityIdForCurrentPage()
if id == nil then
return nil
@@ -40,19 +62,13 @@
-- Get the mw.wikibase.entity object for the current page
wikibase.getEntityObject = function()
- if entity ~= false then
- return entity
- end
-
- local id = php.getEntityId( tostring(
mw.title.getCurrentTitle().prefixedText ) )
+ local id = getEntityIdForCurrentPage()
if id == nil then
- entity = nil
+ return nil
else
- entity = getEntityObject( id )
+ return getEntityObject( id )
end
-
- return entity
end
-- Get the label for the given entity id (in content language)
--
To view, visit https://gerrit.wikimedia.org/r/144935
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I22d4f9d2fd1f01a9bfffde77d6c9c75842e28d9e
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Hoo man <[email protected]>
Gerrit-Reviewer: Aude <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Jackmcbarn <[email protected]>
Gerrit-Reviewer: WikidataJenkins <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits