From 1931caec2baa0aae550ad7d13075d4f15e5bc9cb Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Fri, 11 Mar 2022 20:21:25 +0100 Subject: [PATCH] Fixed sign.php to handle non-continuous id values Signed-off-by: Janos SUTO --- util/sign.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/util/sign.php b/util/sign.php index b3c4110d..d0f8d3e8 100644 --- a/util/sign.php +++ b/util/sign.php @@ -128,27 +128,27 @@ function get_hash_values() { if($last_id == 0) { $start_id = TSA_START_ID; - if(MODE == 'unit') { $stop_id = $start_id + TSA_STAMP_REQUEST_UNIT_SIZE - 1; } - else { $stop_id = 1000000000; } - } - else { + } else { $start_id = $last_id + 1; - if(MODE == 'unit') { $stop_id = $start_id + TSA_STAMP_REQUEST_UNIT_SIZE - 1; } - else { $stop_id = 1000000000; } } - $query = $db->query("SELECT id, digest FROM " . TABLE_META . " WHERE id >= ? AND id <= ? ORDER BY id", array($start_id, $stop_id)); + if(MODE == 'unit') { + $limit = TSA_STAMP_REQUEST_UNIT_SIZE; + } else { + $limit = 100000; // stay well below default PHP memory_limit + } + + $query = $db->query("SELECT id, digest FROM " . TABLE_META . " WHERE id >= ? ORDER BY id LIMIT $limit", array($start_id)); foreach($query->rows as $q) { $count++; + $last_id = $q['id']; $s .= $q['digest']; } - if(MODE == 'time') { $stop_id = $start_id + $count - 1; } - return [ START_ID => $start_id, - STOP_ID => $stop_id, + STOP_ID => $last_id, COUNT => $count, HASH_VALUE => hash(ALGO, $s) ];