|
@@ -2,11 +2,11 @@
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
-use Illuminate\Console\Command;
|
|
|
-use App\Services\AccountService;
|
|
|
+use App\Profile;
|
|
|
use App\Services\Account\AccountStatService;
|
|
|
+use App\Services\AccountService;
|
|
|
use App\Status;
|
|
|
-use App\Profile;
|
|
|
+use Illuminate\Console\Command;
|
|
|
|
|
|
class AccountPostCountStatUpdate extends Command
|
|
|
{
|
|
@@ -29,29 +29,53 @@ class AccountPostCountStatUpdate extends Command
|
|
|
*/
|
|
|
public function handle()
|
|
|
{
|
|
|
- $ids = AccountStatService::getAllPostCountIncr();
|
|
|
- if(!$ids || !count($ids)) {
|
|
|
+ $chunkSize = 100;
|
|
|
+ $lastId = 0;
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ $ids = AccountStatService::getPostCountChunk($lastId, $chunkSize);
|
|
|
+
|
|
|
+ if (empty($ids)) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($ids as $id) {
|
|
|
+ $this->processAccount($id);
|
|
|
+ $lastId = $id;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (function_exists('gc_collect_cycles')) {
|
|
|
+ gc_collect_cycles();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function processAccount($id)
|
|
|
+ {
|
|
|
+ $acct = AccountService::get($id, true);
|
|
|
+ if (! $acct) {
|
|
|
+ AccountStatService::removeFromPostCount($id);
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
- foreach($ids as $id) {
|
|
|
- $acct = AccountService::get($id, true);
|
|
|
- if(!$acct) {
|
|
|
+
|
|
|
+ $statusCount = Status::whereProfileId($id)->count();
|
|
|
+ if ($statusCount != $acct['statuses_count']) {
|
|
|
+ $profile = Profile::find($id);
|
|
|
+ if (! $profile) {
|
|
|
AccountStatService::removeFromPostCount($id);
|
|
|
- continue;
|
|
|
- }
|
|
|
- $statusCount = Status::whereProfileId($id)->count();
|
|
|
- if($statusCount != $acct['statuses_count']) {
|
|
|
- $profile = Profile::find($id);
|
|
|
- if(!$profile) {
|
|
|
- AccountStatService::removeFromPostCount($id);
|
|
|
- continue;
|
|
|
- }
|
|
|
- $profile->status_count = $statusCount;
|
|
|
- $profile->save();
|
|
|
- AccountService::del($id);
|
|
|
+
|
|
|
+ return;
|
|
|
}
|
|
|
- AccountStatService::removeFromPostCount($id);
|
|
|
+
|
|
|
+ $profile->status_count = $statusCount;
|
|
|
+ $profile->save();
|
|
|
+
|
|
|
+ AccountService::del($id);
|
|
|
}
|
|
|
- return;
|
|
|
+
|
|
|
+ AccountStatService::removeFromPostCount($id);
|
|
|
}
|
|
|
}
|