Skip to content

Commit

Permalink
Handle checking for the current update
Browse files Browse the repository at this point in the history
  • Loading branch information
Justasic committed Sep 15, 2021
1 parent 967f4f5 commit 2b9d7b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ public static function selectTelegramUpdate($limit = -1, $id = null)
$redis->expire('telegram_update_ids', 86400);
}

// If the limit is 1 and $id is not null, just return for now
// TODO: maybe make this more reasonable?
if ($id !== null && $limit === 1)
{
$info = $redis->get($id);
if ($info !== null)
return json_decode($info);
else
return false;
}

// Select the most recent $limit keys from the set.
$updates = $redis->lRange('telegram_update_ids', 0, $limit);

Expand All @@ -226,9 +237,7 @@ public static function selectTelegramUpdate($limit = -1, $id = null)
$ret[$update] = json_decode($redis->get($update));
}

// FIXME: use the $id param somehow??

return $ret;
return count($ret) != 0 ? $ret : false;
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions src/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,10 @@ public function processUpdate(Update $update)
}

//Make sure we don't try to process update that was already processed
$last_id = DB::selectTelegramUpdate(1, $this->update->getUpdateId());
$this_id = $this->update->getUpdateId();
$last_id = DB::selectTelegramUpdate(1, $this_id);
if ($last_id && count($last_id) === 1) {
TelegramLog::debug('Duplicate update received, processing aborted!');
TelegramLog::debug("Duplicate update received ($this_id == $last_id), processing aborted!");
return Request::emptyResponse();
}

Expand Down

0 comments on commit 2b9d7b8

Please sign in to comment.