diff --git a/app/Repositories/ClaimRepository.php b/app/Repositories/ClaimRepository.php index c040f262..aa626ad5 100644 --- a/app/Repositories/ClaimRepository.php +++ b/app/Repositories/ClaimRepository.php @@ -128,7 +128,7 @@ class ClaimRepository extends BaseRepository { $startOfThisMonth = Carbon::now()->startOfMonth(); $query = Claim::query() - ->select(['uid', 'count(*) as count']) + ->selectRaw("uid, count(*) as count)") ->where("created_at", "<", $startOfThisMonth) ->where(function (Builder $query) use ($startOfThisMonth) { $query->where('last_settle_at', '<', $startOfThisMonth)->orWhereNull('last_settle_at'); diff --git a/database/migrations/2025_05_13_163426_add_index_to_access_field_of_iplog_table.php b/database/migrations/2025_05_13_163426_add_index_to_access_field_of_iplog_table.php new file mode 100644 index 00000000..8e1413f4 --- /dev/null +++ b/database/migrations/2025_05_13_163426_add_index_to_access_field_of_iplog_table.php @@ -0,0 +1,28 @@ +index('access'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('iplog', function (Blueprint $table) { + // + }); + } +}; diff --git a/include/cleanup.php b/include/cleanup.php index 8dd56659..1d057b0f 100644 --- a/include/cleanup.php +++ b/include/cleanup.php @@ -938,6 +938,28 @@ function docleanup($forceAll = 0, $printProgress = false) { printProgress($log); } + //delete old ip log + $length = 90*86400; //90 days + $until = date("Y-m-d H:i:s",(TIMENOW - $length)); + sql_query("DELETE FROM iplog WHERE access < ".sqlesc($until)); + $log = "delete old ip log"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + //delete failed jobs + $length = 10*86400; //10 days + $until = date("Y-m-d H:i:s",(TIMENOW - $length)); + sql_query("DELETE FROM failed_jobs WHERE failed_at < ".sqlesc($until)); + $log = "delete failed jobs"; + do_log($log); + if ($printProgress) { + printProgress($log); + } + + + //cost too many time, migrate to schedule run command //sync to Meilisearch // $meiliRep = new \App\Repositories\MeiliSearchRepository(); @@ -1022,16 +1044,6 @@ function docleanup($forceAll = 0, $printProgress = false) { printProgress($log); } - //delete old ip log - $length = 365*86400; //a year - $until = date("Y-m-d H:i:s",(TIMENOW - $length)); - sql_query("DELETE FROM iplog WHERE access < ".sqlesc($until)); - $log = "delete old ip log"; - do_log($log); - if ($printProgress) { - printProgress($log); - } - //delete old general log $until = date("Y-m-d H:i:s",(TIMENOW - $length)); sql_query("DELETE FROM sitelog WHERE added < ".sqlesc($until)) or sqlerr(__FILE__, __LINE__);