1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2024-11-24 11:22:42 +01:00

Fix options caching

This commit is contained in:
FreeScout 2018-11-27 22:05:13 -08:00
parent 0c413261b4
commit 9bd0dda3dd
2 changed files with 23 additions and 5 deletions

View File

@ -9,6 +9,9 @@ use Illuminate\Database\Eloquent\Model;
class Option extends Model class Option extends Model
{ {
// Value returned when cache contains default value.
const CACHE_DEFAULT_VALUE = 'CACHE_DEFAULT_VALUE';
// todo: cache like in WordPress (fetch all options from DB each time) // todo: cache like in WordPress (fetch all options from DB each time)
public static $cache = []; public static $cache = [];
@ -76,7 +79,11 @@ class Option extends Model
} }
if (isset(self::$cache[$name])) { if (isset(self::$cache[$name])) {
return self::$cache[$name]; if (self::$cache[$name] == self::CACHE_DEFAULT_VALUE) {
return $default;
} else {
return self::$cache[$name];
}
} }
$option = self::where('name', (string) $name)->first(); $option = self::where('name', (string) $name)->first();
@ -86,12 +93,12 @@ class Option extends Model
} else { } else {
$value = $option->value; $value = $option->value;
} }
self::$cache[$name] = $value;
} else { } else {
$value = $default; $value = $default;
self::$cache[$name] = self::CACHE_DEFAULT_VALUE;
} }
self::$cache[$name] = $value;
return $value; return $value;
} }
@ -142,7 +149,14 @@ class Option extends Model
// Return if we can get all options from cache // Return if we can get all options from cache
foreach ($options as $name) { foreach ($options as $name) {
if (isset(self::$cache[$name])) { if (isset(self::$cache[$name])) {
$values[$name] = self::$cache[$name]; if (self::$cache[$name] == self::CACHE_DEFAULT_VALUE) {
if (empty($defaults[$name])) {
$default = self::getDefault($name);
}
$values[$name] = $default;
} else {
$values[$name] = self::$cache[$name];
}
} }
} }
if (count($values) == count($options)) { if (count($values) == count($options)) {
@ -165,11 +179,12 @@ class Option extends Model
} else { } else {
$value = $db_option->value; $value = $db_option->value;
} }
self::$cache[$name] = $value;
} else { } else {
$value = $default; $value = $default;
self::$cache[$name] = self::CACHE_DEFAULT_VALUE;
} }
self::$cache[$name] = $value;
$values[$name] = $value; $values[$name] = $value;
} }

View File

@ -2718,6 +2718,9 @@ ul.prev-convs {
.margin-bottom-0 { .margin-bottom-0 {
margin-bottom: 0 !important; margin-bottom: 0 !important;
} }
.margin-bottom-10 {
margin-bottom: 10px !important;
}
.margin-bottom-30 { .margin-bottom-30 {
margin-bottom: 30px !important; margin-bottom: 30px !important;
} }