Smuggli has submitted this change and it was merged.

Change subject: Added cache support for total count
......................................................................


Added cache support for total count

Added wfDebugLog statements
Fixed variable name
Log message was wrong

Change-Id: Iffee6831d391b9103fc639260405d207ead3d814
---
M ShoutBox/ShoutBox.class.php
1 file changed, 27 insertions(+), 13 deletions(-)

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



diff --git a/ShoutBox/ShoutBox.class.php b/ShoutBox/ShoutBox.class.php
index e424930..e8a88e0 100644
--- a/ShoutBox/ShoutBox.class.php
+++ b/ShoutBox/ShoutBox.class.php
@@ -370,18 +370,31 @@
         * @return int number of shouts
         */
        public static function getTotalShouts( $iArticleId = 0 ) {
-               $aTables = array( 'bs_shoutbox' );
-               $aFields = array( 'sb_id' );
-               $aConditions = array(
-                       'sb_page_id' => $iArticleId,
-                       'sb_archived' => '0',
-                       'sb_parent_id' => '0',
-                       'sb_title' => '',
-               );
-               $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select( $aTables, $aFields, $aConditions, 
__METHOD__ );
-               $iTotelShouts = $res !== false ? $dbr->numRows( $res ) : 0;
-               return $iTotelShouts;
+               $sKey = BsCacheHelper::getCacheKey( 'BlueSpice', 'ShoutBox', 
'totalCount' . $iArticleId );
+               $iData = BsCacheHelper::get( $sKey );
+
+               if ( $iData === false ) {
+                       wfDebugLog( 'BsMemcached', __CLASS__ . ': Fetching 
total count from DB' );
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $res = $dbr->select(
+                               'bs_shoutbox',
+                               'sb_id',
+                               array(
+                                       'sb_page_id' => $iArticleId,
+                                       'sb_archived' => '0',
+                                       'sb_parent_id' => '0',
+                                       'sb_title' => '',
+                               ),
+                               __METHOD__
+                       );
+                       $iTotalShouts = $res !== false ? $dbr->numRows( $res ) 
: 0;
+
+                       BsCacheHelper::set( $sKey, $iTotalShouts );
+               } else {
+                       wfDebugLog( 'BsMemcached', __CLASS__ . ': Fetching 
total count from cache' );
+                       $iTotalShouts = $iData;
+               }
+               return $iTotalShouts;
        }
 
        /**
@@ -468,7 +481,7 @@
                                'bs_shoutbox', array( 'sb_archived' => '1' ), 
array( 'sb_id' => $iShoutId )
                );
 
-               self::invalidateShoutBoxCache( (int) $iArticleId );
+               self::invalidateShoutBoxCache( $iArticleId );
                $sResponse = $res == true ? 'bs-shoutbox-archive-success' : 
'bs-shoutbox-archive-failure';
                $sOutput = wfMessage( $sResponse )->plain();
                return $sOutput;
@@ -476,6 +489,7 @@
 
        public static function invalidateShoutBoxCache( $iArticleId ) {
                BsCacheHelper::invalidateCache( BsCacheHelper::getCacheKey( 
'BlueSpice', 'ShoutBox', $iArticleId ) );
+               BsCacheHelper::invalidateCache( BsCacheHelper::getCacheKey( 
'BlueSpice', 'ShoutBox', 'totalCount' . $iArticleId ) );
        }
 
        /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iffee6831d391b9103fc639260405d207ead3d814
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/BlueSpiceExtensions
Gerrit-Branch: master
Gerrit-Owner: Smuggli <mug...@hallowelt.biz>
Gerrit-Reviewer: Mglaser <gla...@hallowelt.biz>
Gerrit-Reviewer: Pigpen <reym...@hallowelt.biz>
Gerrit-Reviewer: Robert Vogel <vo...@hallowelt.biz>
Gerrit-Reviewer: Smuggli <mug...@hallowelt.biz>
Gerrit-Reviewer: Swidmann <widm...@hallowelt.biz>

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

Reply via email to