Physikerwelt has submitted this change and it was merged.

Change subject: Buffer png writes and flush them all at once
......................................................................


Buffer png writes and flush them all at once

* This should half the time to render pages with many formulas

bug: 56769
Change-Id: I5edf979c31fe12098eba1d1df52c9cd3251bd115
---
M .gitignore
M MathTexvc.php
2 files changed, 18 insertions(+), 7 deletions(-)

Approvals:
  Physikerwelt: Verified; Looks good to me, approved



diff --git a/.gitignore b/.gitignore
index 3417dd2..f91b1cb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
 *~
 *.kate-swp
 .*.swp
+/nbproject/private/
\ No newline at end of file
diff --git a/MathTexvc.php b/MathTexvc.php
index 78bd39f..6f83a98 100644
--- a/MathTexvc.php
+++ b/MathTexvc.php
@@ -126,7 +126,7 @@
         * @return int|string MW_TEXVC_SUCCESS or error string
         */
        public function callTexvc() {
-               global $wgTexvc, $wgTexvcBackgroundColor, $wgUseSquid, 
$wgMathCheckFiles;
+               global $wgTexvc, $wgTexvcBackgroundColor, $wgUseSquid, 
$wgMathCheckFiles, $wgHooks;
 
                wfProfileIn( __METHOD__ );
                $tmpDir = wfTempDir();
@@ -237,13 +237,23 @@
                        return $this->getError( 'math_output_error' );
                }
                // Store the file at the final storage path...
-               if ( !$backend->quickStore( array(
-                       'src' => "$tmpDir/{$this->getHash()}.png", 'dst' => 
"$hashpath/{$this->getHash()}.png"
-               ) )->isOK()
-               ) {
-                       wfProfileOut( __METHOD__ );
-                       return $this->getError( 'math_output_error' );
+               // Bug 56769: buffer the writes and do them at the end.
+               if ( !isset( $wgHooks['ParserAfterParse']['FlushMathBackend'] ) 
) {
+                       $backend->mathBufferedWrites = array();
+                       $wgHooks['ParserAfterParse']['FlushMathBackend'] = 
function() use ( $backend ) {
+                               global $wgHooks;
+                               unset( 
$wgHooks['ParserAfterParse']['FlushMathBackend'] );
+                               $backend->doQuickOperations( 
$backend->mathBufferedWrites );
+                               unset( $backend->mathBufferedWrites );
+                       };
                }
+               $backend->mathBufferedWrites[] = array(
+                       'op'  => 'store',
+                       'src' => "$tmpDir/{$this->getHash()}.png",
+                       'dst' => "$hashpath/{$this->getHash()}.png",
+                       'ref' => $tempFsFile // keep file alive
+               );
+
                wfProfileOut( __METHOD__ );
                return self::MW_TEXVC_SUCCESS;
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/103644
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5edf979c31fe12098eba1d1df52c9cd3251bd115
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Physikerwelt <w...@physikerwelt.de>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to