Skip to content

Commit 02545a9

Browse files
committed
add missing keys to cached translations
1 parent eca04e4 commit 02545a9

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Manager.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,11 @@ function firstOrNewTranslation($attributes = null)
276276
&& array_key_exists('locale', $attributes) && array_key_exists('key', $attributes)
277277
&& array_key_exists($attributes['locale'], $this->preloadedGroupLocales)
278278
) {
279+
$checkDB = false;
280+
279281
if (array_key_exists($attributes['key'], $this->preloadedGroupKeys)
280282
&& array_key_exists($attributes['locale'], $this->preloadedGroupKeys[$attributes['key']])
281283
) {
282-
$checkDB = false;
283284
$translation = $this->preloadedGroupKeys[$attributes['key']][$attributes['locale']];
284285
}
285286
}
@@ -298,6 +299,9 @@ function firstOrNewTranslation($attributes = null)
298299
$translation = new Translation();
299300
$translation->fill($attributes);
300301
$translation->setConnection($this->getConnectionName());
302+
303+
// put it in the cache as empty so we don't hit the database every time
304+
$this->cacheTranslation('', $translation->group, $translation->key, null, $translation->locale);
301305
}
302306

303307
return $translation;
@@ -308,6 +312,9 @@ function firstOrCreateTranslation($attributes = null)
308312
$translation = $this->firstOrNewTranslation($attributes);
309313
if (!$translation->exists) {
310314
$translation->save();
315+
316+
// put it in the cache as empty so we don't hit the database every time
317+
$this->cacheTranslation('', $translation->group, $translation->key, null, $translation->locale);
311318
}
312319

313320
return $translation;

versioninfo.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ The 1.x.x versions are for Laravel 4.2, 2.1.x versions are for Laravel 5.1+, 2.3
77

88
* Fix: unpublished mode shows groups not in LTM database as undefined.
99
* Fix: unpublished mode showing translations marked deleted instead of as undefined
10+
* Fix: add missing keys to the cache to not thrash the database on every access to their
11+
translations
1012

1113
#### 2.6.28
1214

0 commit comments

Comments
 (0)