Browse Source

Update Instance total post, add optional estimation for huge status tables

Daniel Supernault 3 months ago
parent
commit
5a5821fe86
2 changed files with 7 additions and 1 deletions
  1. 5 1
      app/Console/Commands/InstanceUpdateTotalLocalPosts.php
  2. 2 0
      config/instance.php

+ 5 - 1
app/Console/Commands/InstanceUpdateTotalLocalPosts.php

@@ -77,10 +77,14 @@ class InstanceUpdateTotalLocalPosts extends Command
 
 
     protected function getTotalLocalPosts()
     protected function getTotalLocalPosts()
     {
     {
+        if ((bool) config('instance.total_count_estimate') && config('database.default') === 'mysql') {
+            return DB::select("EXPLAIN SELECT COUNT(*) FROM statuses WHERE deleted_at IS NULL AND local = 1 AND type != 'share'")[0]->rows;
+        }
+
         return DB::table('statuses')
         return DB::table('statuses')
             ->whereNull('deleted_at')
             ->whereNull('deleted_at')
             ->where('local', true)
             ->where('local', true)
-            ->whereNot('type', 'share') # Ignore boosts for the post count
+            ->whereNot('type', 'share')
             ->count();
             ->count();
     }
     }
 }
 }

+ 2 - 0
config/instance.php

@@ -188,4 +188,6 @@ return [
     'show_peers' => env('INSTANCE_SHOW_PEERS', false),
     'show_peers' => env('INSTANCE_SHOW_PEERS', false),
 
 
     'allow_new_account_dms' => env('INSTANCE_ALLOW_NEW_DMS', true),
     'allow_new_account_dms' => env('INSTANCE_ALLOW_NEW_DMS', true),
+
+    'total_count_estimate' => env('INSTANCE_TOTAL_POSTS_COUNT_ESTIMATE', false),
 ];
 ];