Explorar o código

Update InstanceService, fix total post count when config_cache is disabled

Daniel Supernault hai 1 semana
pai
achega
f0bc9d66e4
Modificáronse 1 ficheiros con 13 adicións e 2 borrados
  1. 13 2
      app/Services/InstanceService.php

+ 13 - 2
app/Services/InstanceService.php

@@ -4,7 +4,8 @@ namespace App\Services;
 
 use App\Instance;
 use App\Util\Blurhash\Blurhash;
-use Cache;
+use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\DB;
 
 class InstanceService
 {
@@ -100,7 +101,17 @@ class InstanceService
 
     public static function totalLocalStatuses()
     {
-        return config_cache('instance.stats.total_local_posts');
+        if (config('instance.enable_cc')) {
+            return config_cache('instance.stats.total_local_posts');
+        }
+
+        return Cache::remember(self::CACHE_KEY_TOTAL_POSTS, now()->addHour(), function () {
+            return DB::table('statuses')
+                ->whereNull('deleted_at')
+                ->where('local', true)
+                ->whereNot('type', 'share')
+                ->count();
+        });
     }
 
     public static function headerBlurhash()