Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
perf(tracker): No need to explicit serialize announce data
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Jul 25, 2019
1 parent b4543b1 commit 68e4550
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions apps/controllers/TrackerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -787,12 +787,12 @@ private function sendToTaskWorker($queries, $role, $userInfo, $torrentInfo)
* Don't use json_{encode,decode} for the value of info_hash and peer_id will make
* those function return FALSE
*/
return app()->redis->lPush('Tracker:to_deal_queue', serialize([
return app()->redis->lPush('Tracker:to_deal_queue', [
'timestamp' => time(),
'queries' => $queries,
'role' => $role,
'userInfo' => $userInfo,
'torrentInfo' => $torrentInfo
]));
]);
}
}
8 changes: 3 additions & 5 deletions apps/timer/TrackerAnnounceTimer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ class TrackerAnnounceTimer extends Timer
public function init()
{
while (true) {
$data_raw = app()->redis->brpoplpush('Tracker:to_deal_queue', 'Tracker:backup_queue', 5);
if ($data_raw !== false) {
$data = unserialize($data_raw);
$data = app()->redis->brpoplpush('Tracker:to_deal_queue', 'Tracker:backup_queue', 5);
if ($data !== false) {
app()->pdo->beginTransaction();
try {
$this->processAnnounceRequest($data['queries'], $data['role'], $data['userInfo'], $data['torrentInfo']);
app()->pdo->commit();
app()->redis->lRem('Tracker:backup_queue', $data_raw, 0);
app()->redis->lRem('Tracker:backup_queue', $data, 0);
} catch (\Exception $e) {
println($e->getMessage());
app()->pdo->rollback();
Expand All @@ -34,7 +33,6 @@ public function init()
}
}


/** TODO 2018.12.12 Check Muti-Tracker behaviour when a Transaction begin
* @param $queries
* @param $seeder
Expand Down

0 comments on commit 68e4550

Please sign in to comment.