jenkins-bot has submitted this change and it was merged.
Change subject: Added common metadata caching to the djvu handler
......................................................................
Added common metadata caching to the djvu handler
* This should reduce expensive metadata fetches
for djvu files with large (~2mb) img_metadata
Bug: T96360
Change-Id: I7273ea083f90948f8c1d8948a64929bfb759ee72
(cherry picked from commit 746c8ddc1d521f5202424330d86caacf15154159)
---
M includes/media/DjVu.php
1 file changed, 42 insertions(+), 16 deletions(-)
Approvals:
Chad: Looks good to me, approved
jenkins-bot: Verified
diff --git a/includes/media/DjVu.php b/includes/media/DjVu.php
index 5b57952..749ef23 100644
--- a/includes/media/DjVu.php
+++ b/includes/media/DjVu.php
@@ -376,29 +376,55 @@
}
function pageCount( $image ) {
- $tree = $this->getMetaTree( $image );
- if ( !$tree ) {
- return false;
+ global $wgMemc;
+
+ $key = wfMemcKey( 'file-djvu', 'pageCount', $image->getSha1() );
+
+ $count = $wgMemc->get( $key );
+ if ( $count === false ) {
+ $tree = $this->getMetaTree( $image );
+ if ( !$tree ) {
+ return false;
+ }
+ $count = count( $tree->xpath( '//OBJECT' ) );
+ $wgMemc->set( $key, $count );
}
- return count( $tree->xpath( '//OBJECT' ) );
+ return $count;
}
function getPageDimensions( $image, $page ) {
- $tree = $this->getMetaTree( $image );
- if ( !$tree ) {
- return false;
+ global $wgMemc;
+
+ $key = wfMemcKey( 'file-djvu', 'dimensions', $image->getSha1()
);
+
+ $dimsByPage = $wgMemc->get( $key );
+ if ( !is_array( $dimsByPage ) ) {
+ $tree = $this->getMetaTree( $image );
+ if ( !$tree ) {
+ return false;
+ }
+
+ $dimsByPage = array();
+ $count = count( $tree->xpath( '//OBJECT' ) );
+ for ( $i = 0; $i < $count; ++$i ) {
+ $o = $tree->BODY[0]->OBJECT[$i];
+ if ( $o ) {
+ $dimsByPage[$i] = array(
+ 'width' => (int)$o['width'],
+ 'height' => (int)$o['height']
+ );
+ } else {
+ $dimsByPage[$i] = false;
+ }
+ }
+
+ $wgMemc->set( $key, $dimsByPage );
}
- $o = $tree->BODY[0]->OBJECT[$page - 1];
- if ( $o ) {
- return array(
- 'width' => intval( $o['width'] ),
- 'height' => intval( $o['height'] )
- );
- } else {
- return false;
- }
+ $index = $page - 1; // MW starts pages at 1
+
+ return isset( $dimsByPage[$index] ) ? $dimsByPage[$index] :
false;
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/210409
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7273ea083f90948f8c1d8948a64929bfb759ee72
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: wmf/1.26wmf5
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Tpt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits