Comments

edurenye created an issue. See original summary.

edurenye’s picture

Status: Active » Needs review
StatusFileSize
new2.12 KB

Added cache for remote languages.

miro_dietiker’s picture

And how long is the cache persisted?
What if the provider adds a language and it doesn't show up to the end user?

Do we need to offer a Clear / update button to the user in the translator?

berdir’s picture

We already have identical caching for two language calls. You have to resave the translator or do any other form of cache clearing already in such a case.

miro_dietiker’s picture

Yeah i see that in the diff. :-)
I think we should do a followup about the UX aspect of that.

berdir’s picture

Status: Needs review » Needs work
+++ b/src/Entity/Translator.php
@@ -343,8 +343,12 @@ class Translator extends ConfigEntityBase implements TranslatorInterface {
       if (empty($this->remoteLanguages)) {
         $this->remoteLanguages = $plugin->getSupportedRemoteLanguages($this);
+        $this->updateCache();
       }
     }

As discussed, the current pattern of writing all caches on every change is a lot of overhead.

We should only do the specific cache set in each method, atleast here for the new one, OK if we don't update the existing ones.

edurenye’s picture

Status: Needs work » Needs review
StatusFileSize
new2.09 KB
new1.28 KB

Done, changed just the new one.

berdir’s picture

Status: Needs review » Needs work
+++ b/src/Entity/Translator.php
@@ -348,7 +348,7 @@ class Translator extends ConfigEntityBase implements TranslatorInterface {
       }
       if (empty($this->remoteLanguages)) {
         $this->remoteLanguages = $plugin->getSupportedRemoteLanguages($this);
-        $this->updateCache();
+        \Drupal::cache('data')->set('tmgmt_remote_languages:' . $this->name, $this->remoteLanguages, Cache::PERMANENT, $this->getCacheTags());

@@ -469,7 +469,6 @@ class Translator extends ConfigEntityBase implements TranslatorInterface {
       $info = $plugin->getPluginDefinition();
       if (!isset($info['language cache']) || !empty($info['language cache'])) {
-        \Drupal::cache('data')->set('tmgmt_remote_languages:' . $this->name, $this->remoteLanguages, Cache::PERMANENT, $this->getCacheTags());

almost ;)

what we are missing now is the check if languages should be cached, we have to check that here as well.

not even sure that works properly, because I don't think you can have an annotation property with spaces..?

edurenye’s picture

Status: Needs work » Needs review
StatusFileSize
new2.35 KB
new1.51 KB

Done those changes.

edurenye’s picture

Fixed incoherence.

  • Berdir committed a6b6d35 on 8.x-1.x authored by edurenye
    Issue #2712955 by edurenye: Add cache to remote languages
    
berdir’s picture

Status: Needs review » Fixed

Thanks, committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.