Update ConfigCacheService, fix database race condition and fallback to file config and enable by default

This commit is contained in:
Daniel Supernault 2024-05-07 01:00:32 -06:00
parent cbf996c9b6
commit 60a62b59c9
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
3 changed files with 133 additions and 129 deletions

View file

@ -67,7 +67,7 @@ ADMIN_DOMAIN="${APP_DOMAIN}"
# @default "false" # @default "false"
# @see https://docs.pixelfed.org/technical-documentation/config/#config_cache # @see https://docs.pixelfed.org/technical-documentation/config/#config_cache
# @dottie/validate required,boolean # @dottie/validate required,boolean
ENABLE_CONFIG_CACHE="false" ENABLE_CONFIG_CACHE="true"
# Enable/disable new local account registrations. # Enable/disable new local account registrations.
# #

View file

@ -8,7 +8,7 @@ OPEN_REGISTRATION="false"
ENFORCE_EMAIL_VERIFICATION="false" ENFORCE_EMAIL_VERIFICATION="false"
PF_MAX_USERS="1000" PF_MAX_USERS="1000"
OAUTH_ENABLED="true" OAUTH_ENABLED="true"
ENABLE_CONFIG_CACHE=false ENABLE_CONFIG_CACHE=true
# Media Configuration # Media Configuration
PF_OPTIMIZE_IMAGES="true" PF_OPTIMIZE_IMAGES="true"

View file

@ -4,6 +4,7 @@ namespace App\Services;
use App\Models\ConfigCache as ConfigCacheModel; use App\Models\ConfigCache as ConfigCacheModel;
use Cache; use Cache;
use Illuminate\Database\QueryException;
class ConfigCacheService class ConfigCacheService
{ {
@ -25,8 +26,8 @@ class ConfigCacheService
return config($key); return config($key);
} }
try {
return Cache::remember($cacheKey, $ttl, function () use ($key) { return Cache::remember($cacheKey, $ttl, function () use ($key) {
$allowed = [ $allowed = [
'app.name', 'app.name',
'app.short_description', 'app.short_description',
@ -175,6 +176,9 @@ class ConfigCacheService
return $v; return $v;
}); });
} catch (Exception | QueryException $e) {
return config($key);
}
} }
public static function put($key, $val) public static function put($key, $val)