mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
clear claim stats cache
This commit is contained in:
@@ -13,6 +13,8 @@ use Nexus\Database\NexusDB;
|
|||||||
|
|
||||||
class ClaimRepository extends BaseRepository
|
class ClaimRepository extends BaseRepository
|
||||||
{
|
{
|
||||||
|
const STAT_CACHE_PREFIX = 'claim_stats_';
|
||||||
|
|
||||||
public function getList(array $params)
|
public function getList(array $params)
|
||||||
{
|
{
|
||||||
$query = Claim::query()->with(['family']);
|
$query = Claim::query()->with(['family']);
|
||||||
@@ -59,6 +61,7 @@ class ClaimRepository extends BaseRepository
|
|||||||
'seed_time_begin' => $snatch->seedtime,
|
'seed_time_begin' => $snatch->seedtime,
|
||||||
'uploaded_begin' => $snatch->uploaded,
|
'uploaded_begin' => $snatch->uploaded,
|
||||||
];
|
];
|
||||||
|
$this->clearStatsCache($uid);
|
||||||
return Claim::query()->create($insert);
|
return Claim::query()->create($insert);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,6 +90,7 @@ class ClaimRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
$deductBonus = Claim::getConfigGiveUpDeductBonus();
|
$deductBonus = Claim::getConfigGiveUpDeductBonus();
|
||||||
return NexusDB::transaction(function () use ($model, $deductBonus) {
|
return NexusDB::transaction(function () use ($model, $deductBonus) {
|
||||||
|
$this->clearStatsCache($model->uid);
|
||||||
User::query()->where('id', $model->uid)->decrement('seedbonus', $deductBonus);
|
User::query()->where('id', $model->uid)->decrement('seedbonus', $deductBonus);
|
||||||
do_log(sprintf("[GIVE_UP_CLAIM_TORRENT], user: %s, deduct bonus: %s", $model->uid, $deductBonus), 'alert');
|
do_log(sprintf("[GIVE_UP_CLAIM_TORRENT], user: %s, deduct bonus: %s", $model->uid, $deductBonus), 'alert');
|
||||||
return $model->delete();
|
return $model->delete();
|
||||||
@@ -95,13 +99,18 @@ class ClaimRepository extends BaseRepository
|
|||||||
|
|
||||||
public function getStats($uid)
|
public function getStats($uid)
|
||||||
{
|
{
|
||||||
$key = "claim_stats_$uid";
|
$key = self::STAT_CACHE_PREFIX . $uid;
|
||||||
return NexusDB::remember($key, 60, function () use ($uid) {
|
return NexusDB::remember($key, 3600, function () use ($uid) {
|
||||||
$max = Claim::getConfigTorrentUpLimit();
|
$max = Claim::getConfigTorrentUpLimit();
|
||||||
return sprintf('%s/%s', Claim::query()->where('uid', $uid)->count(), $max);
|
return sprintf('%s/%s', Claim::query()->where('uid', $uid)->count(), $max);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function clearStatsCache($uid)
|
||||||
|
{
|
||||||
|
NexusDB::cache_del(self::STAT_CACHE_PREFIX . $uid);
|
||||||
|
}
|
||||||
|
|
||||||
public function settleCronjob(): array
|
public function settleCronjob(): array
|
||||||
{
|
{
|
||||||
$startOfThisMonth = Carbon::now()->startOfMonth();
|
$startOfThisMonth = Carbon::now()->startOfMonth();
|
||||||
|
|||||||
Reference in New Issue
Block a user