Skip to content

Commit

Permalink
Don't vary cache on URL protocol or image size
Browse files Browse the repository at this point in the history
The protocol is ininfluent, the size also seems to be so, and this way
we can prefetch the next image for on-wiki requests.

Bug: T286356
  • Loading branch information
Daimona committed Jul 15, 2021
1 parent 8fc5eb5 commit bd292c2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Controller/OcrController.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private function getText(): string
$cacheKey = md5(implode(
'|',
[
$this->imageUrl,
self::transformImageURLForCacheKey($this->imageUrl),
static::$params['engine'],
implode('|', static::$params['langs']),
static::$params['psm'],
Expand All @@ -237,4 +237,19 @@ private function getText(): string
return $this->engine->getText($this->imageUrl, static::$params['langs']);
});
}

/**
* Make an image URL suitable to be used as a cache key (e.g. strip protocol)
* @param string $url
* @return string
*/
private static function transformImageURLForCacheKey(string $url): string
{
// Strip size, see T286356.
return preg_replace(
'/(page\d+-)\d+px/',
'$1',
preg_replace('/^https?:/i', '', $url)
);
}
}

0 comments on commit bd292c2

Please sign in to comment.