Переглянути джерело

Fix server post stats
This fixes the homepage, showing how many posts have been made by the
server.
The prior logic includes posts from remote servers by an indirect check
for if it's a local post.
This commit changes the query behavior to directly check for the local
flag in the statuses column, and additionally excludes shares

Anil Kulkarni 3 місяців тому
батько
коміт
8db8258cab
1 змінених файлів з 11 додано та 4 видалено
  1. 11 4
      app/Console/Commands/InstanceUpdateTotalLocalPosts.php

+ 11 - 4
app/Console/Commands/InstanceUpdateTotalLocalPosts.php

@@ -53,9 +53,8 @@ class InstanceUpdateTotalLocalPosts extends Command
 
 
     protected function initCache()
     protected function initCache()
     {
     {
-        $count = DB::table('statuses')->whereNull(['url', 'deleted_at'])->count();
         $res = [
         $res = [
-            'count' => $count,
+            'count' => $this->getTotalLocalPosts(),
         ];
         ];
         Storage::put('total_local_posts.json', json_encode($res, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
         Storage::put('total_local_posts.json', json_encode($res, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
         ConfigCacheService::put('instance.stats.total_local_posts', $res['count']);
         ConfigCacheService::put('instance.stats.total_local_posts', $res['count']);
@@ -68,12 +67,20 @@ class InstanceUpdateTotalLocalPosts extends Command
 
 
     protected function updateAndCache()
     protected function updateAndCache()
     {
     {
-        $count = DB::table('statuses')->whereNull(['url', 'deleted_at'])->count();
         $res = [
         $res = [
-            'count' => $count,
+            'count' => $this->getTotalLocalPosts(),
         ];
         ];
         Storage::put('total_local_posts.json', json_encode($res, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
         Storage::put('total_local_posts.json', json_encode($res, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
         ConfigCacheService::put('instance.stats.total_local_posts', $res['count']);
         ConfigCacheService::put('instance.stats.total_local_posts', $res['count']);
 
 
     }
     }
+
+    protected function getTotalLocalPosts()
+    {
+        return DB::table('statuses')
+            ->whereNull('deleted_at')
+            ->where('local', true)
+            ->whereNot('type', 'share') # Ignore boosts for the post count
+            ->count();
+    }
 }
 }