commit 359b672a1755471d1caaed5e6bb373ea441346ef
Author: Abijeet Patro <abijeetpatro@gmail.com>
Date:   Wed Jul 3 19:27:33 2024 +0530

    WANObjectCache: Store source page ids as string and set as segmentable
    
    Storing the message bundle and translatable page ids as comma
    separated strings in the cache. Also adding a trailing comma in
    order to make contains search simpler.
    
    Update cache version and also mark the cache as segmentable.
    
    Bug: T366455
    Change-Id: I1d5af304bdc1d3313c555e14a187aa722cd81723

diff --git a/src/MessageBundleTranslation/MessageBundle.php b/src/MessageBundleTranslation/MessageBundle.php
index 7acede730..4c9dc080e 100644
--- a/src/MessageBundleTranslation/MessageBundle.php
+++ b/src/MessageBundleTranslation/MessageBundle.php
@@ -58,24 +58,28 @@ class MessageBundle extends TranslatableBundle {
 		$cache = $mwServices->getMainWANObjectCache();
 		$cacheKey = $cache->makeKey( 'messagebundle', 'source' );
 
-		$translatablePageIds = $cache->getWithSetCallback(
+		$messageBundleIds = $cache->getWithSetCallback(
 			$cacheKey,
 			$cache::TTL_HOUR * 2,
 			static function ( $oldValue, &$ttl, array &$setOpts ) use ( $mwServices ) {
 				$dbr = $mwServices->getDBLoadBalancer()->getConnection( DB_REPLICA );
 				$setOpts += Database::getCacheSetOptions( $dbr );
 
-				return RevTagStore::getTranslatableBundleIds( RevTagStore::MB_VALID_TAG );
+				$messageBundleIds = RevTagStore::getTranslatableBundleIds( RevTagStore::MB_VALID_TAG );
+				// Adding a comma at the end so that we can check for existence with '12345,'
+				// Without the comma, '12345' will match '123456'.
+				return implode( ',', $messageBundleIds ) . ',';
 			},
 			[
 				'checkKeys' => [ $cacheKey ],
 				'pcTTL' => $cache::TTL_PROC_SHORT,
 				'pcGroup' => __CLASS__ . ':1',
-				'version' => 2,
+				'segmentable' => true,
+				'version' => 3,
 			]
 		);
 
-		return isset( $translatablePageIds[$title->getArticleID()] );
+		return str_contains( $messageBundleIds, ( $title->getArticleID() . ',' ) );
 	}
 
 	public static function clearSourcePageCache(): void {
diff --git a/src/MessageGroupProcessing/RevTagStore.php b/src/MessageGroupProcessing/RevTagStore.php
index f104af143..288584220 100644
--- a/src/MessageGroupProcessing/RevTagStore.php
+++ b/src/MessageGroupProcessing/RevTagStore.php
@@ -191,7 +191,7 @@ class RevTagStore {
 			->fetchResultSet();
 		$results = [];
 		foreach ( $res as $row ) {
-			$results[$row->rt_page] = true;
+			$results[] = (int)$row->rt_page;
 		}
 
 		return $results;
diff --git a/src/PageTranslation/TranslatablePage.php b/src/PageTranslation/TranslatablePage.php
index dbb8f26ba..fec195f28 100644
--- a/src/PageTranslation/TranslatablePage.php
+++ b/src/PageTranslation/TranslatablePage.php
@@ -508,19 +508,24 @@ class TranslatablePage extends TranslatableBundle {
 				$dbr = MediaWikiServices::getInstance()->getDBLoadBalancer()->getConnection( DB_REPLICA );
 				$setOpts += Database::getCacheSetOptions( $dbr );
 
-				return RevTagStore::getTranslatableBundleIds(
+				$translatablePageIds = RevTagStore::getTranslatableBundleIds(
 					RevTagStore::TP_MARK_TAG, RevTagStore::TP_READY_TAG
 				);
+
+				// Adding a comma at the end so that we can check for existence with '12345,'
+				// Without the comma, '12345' will match '123456'.
+				return implode( ',', $translatablePageIds ) . ',';
 			},
 			[
 				'checkKeys' => [ $cacheKey ],
 				'pcTTL' => $cache::TTL_PROC_SHORT,
 				'pcGroup' => __CLASS__ . ':1',
-				'version' => 2,
+				'segmentable' => true,
+				'version' => 3,
 			]
 		);
 
-		return isset( $translatablePageIds[$page->getId()] );
+		return str_contains( $translatablePageIds, ( $page->getId() . ',' ) );
 	}
 
 	/** Clears the source page cache */
