public function getLatestThumbsUrls() { global $wgMemc; $thumbUrls = $wgMemc->get(LatestPhotosController::memcacheKey()); if (empty($thumbUrls)) { // api service $helper = new LatestPhotosHelper(); $params = ['action' => 'query', 'list' => 'logevents', 'letype' => 'upload', 'leprop' => 'title', 'lelimit' => 50]; $apiData = ApiService::call($params); if (empty($apiData)) { $this->response->setVal('thumbUrls', false); } $imageList = $apiData['query']['logevents']; $fileList = array_map([$helper, "getImageData"], $imageList); $fileList = array_filter($fileList, [$helper, "filterImages"]); // make sure the list of images is unique and limited to 11 images (12 including the see all image) $shaList = []; $uniqueList = []; foreach ($fileList as $data) { $sha = $data['file']->sha1; if (!array_key_exists($sha, $shaList) && $data['file']->media_type != 'VIDEO') { $shaList[$sha] = true; $uniqueList[] = $data; } if (count($uniqueList) > 10) { break; } } $thumbUrls = array_map(array($helper, 'getTemplateData'), $uniqueList); $wgMemc->set(self::memcacheKey(), $thumbUrls); } $this->response->setVal('thumbUrls', $thumbUrls); }
private static function avoidUpdateRace() { global $wgMemc; // avoid a race in update event propgation by deleting key after 10 seconds // Memcache delete with a timeout is not implemented, but we can use set to fake it $thumbUrls = $wgMemc->get(LatestPhotosController::memcacheKey()); if (!empty($thumbUrls)) { $wgMemc->set(LatestPhotosController::memcacheKey(), $thumbUrls, 10); } }
public static function onMessageCacheReplace($title, $text) { global $wgMemc; if ($title == self::BLACKLIST_MESSAGE) { wfDebug(__METHOD__ . ": photos blacklist has been updated\n"); $wgMemc->delete(LatestPhotosController::memcacheKey()); } return true; }