Skip to content

Commit

Permalink
Add a cache to avoid computing language order many times during a req…
Browse files Browse the repository at this point in the history
…uest
  • Loading branch information
osma committed Feb 15, 2019
1 parent 566cb2a commit c10bd71
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions model/VocabularyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class VocabularyConfig extends BaseConfig
{
private $plugins;
private $languageOrderCache = array();

public function __construct($resource, $globalPlugins=array())
{
Expand Down Expand Up @@ -433,6 +434,9 @@ public function getTypes($lang = null)
*/
public function getLanguageOrder($clang)
{
if (array_key_exists($clang, $this->languageOrderCache)) {
return $this->languageOrderCache[$clang];
}
$ret = array($clang);
$fallbacks = !empty($this->resource->get('skosmos:fallbackLanguages')) ? $this->resource->get('skosmos:fallbackLanguages') : array();
foreach ($fallbacks as $lang) {
Expand All @@ -448,6 +452,8 @@ public function getLanguageOrder($clang)
$ret[] = $lang;
}
}
// store in cache so this doesn't have to be computed again
$this->languageOrderCache[$clang] = $ret;
return $ret;
}

Expand Down

0 comments on commit c10bd71

Please sign in to comment.