Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update AP helpers, more efficently update post counts
- Loading branch information
Showing
4 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Illuminate\Console\Command; | ||
use App\Services\AccountService; | ||
use App\Services\Account\AccountStatService; | ||
use App\Status; | ||
use App\Profile; | ||
|
||
class AccountPostCountStatUpdate extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'app:account-post-count-stat-update'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Update post counts from recent activities'; | ||
|
||
/** | ||
* Execute the console command. | ||
*/ | ||
public function handle() | ||
{ | ||
$ids = AccountStatService::getAllPostCountIncr(); | ||
if(!$ids || !count($ids)) { | ||
return; | ||
} | ||
foreach($ids as $id) { | ||
$acct = AccountService::get($id, true); | ||
if(!$acct) { | ||
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); | ||
} | ||
AccountStatService::removeFromPostCount($id); | ||
} | ||
return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace App\Services\Account; | ||
|
||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\Redis; | ||
|
||
class AccountStatService | ||
{ | ||
const REFRESH_CACHE_KEY = 'pf:services:accountstats:refresh:daily'; | ||
|
||
public static function incrementPostCount($pid) | ||
{ | ||
return Redis::zadd(self::REFRESH_CACHE_KEY, $pid, $pid); | ||
} | ||
|
||
public static function removeFromPostCount($pid) | ||
{ | ||
return Redis::zrem(self::REFRESH_CACHE_KEY, $pid); | ||
} | ||
|
||
public static function getAllPostCountIncr($limit = -1) | ||
{ | ||
return Redis::zrange(self::REFRESH_CACHE_KEY, 0, $limit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters