Skip to content

Commit 806f9b4

Browse files
authored
Merge pull request #1784 from hashtopolis/dba-change-limit-offset
Replaced all LIMIT comma style queries with LIMIT OFFSET
2 parents 5fe95cd + 5a86730 commit 806f9b4

File tree

7 files changed

+18
-14
lines changed

7 files changed

+18
-14
lines changed

src/chunks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
$numentries = Factory::getChunkFactory()->countFilter([]);
3333
UI::add('maxpage', floor($numentries / $PAGESIZE));
3434
$limit = $page * $PAGESIZE;
35-
$oF = new OrderFilter(Chunk::SOLVE_TIME, "DESC LIMIT $limit, $PAGESIZE", Factory::getChunkFactory());
35+
$oF = new OrderFilter(Chunk::SOLVE_TIME, "DESC LIMIT $PAGESIZE OFFSET $limit", Factory::getChunkFactory());
3636
UI::add('all', false);
3737
UI::add('pageTitle', "Chunks Activity (page " . ($page + 1) . ")");
3838
}

src/cracks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
$qF1 = new QueryFilter(Hash::IS_CRACKED, 1, "=");
7070
$qF2 = new ContainFilter(Hash::HASHLIST_ID, $hashlistIds);
71-
$oF = new OrderFilter(Hash::TIME_CRACKED, "DESC LIMIT " . (SConfig::getInstance()->getVal(DConfig::HASHES_PER_PAGE) * ($currentPage - 1)) . ", " . SConfig::getInstance()->getVal(DConfig::HASHES_PER_PAGE));
71+
$oF = new OrderFilter(Hash::TIME_CRACKED, "DESC LIMIT " . SConfig::getInstance()->getVal(DConfig::HASHES_PER_PAGE) . " OFFSET " . (SConfig::getInstance()->getVal(DConfig::HASHES_PER_PAGE) * ($currentPage - 1)));
7272
$hashes = $hashFactory->filter([Factory::FILTER => [$qF1, $qF2], Factory::ORDER => $oF]);
7373

7474
$crackDetailsPrimary = new DataSet();

src/getFound.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
$limit = 0;
5050
$size = SConfig::getInstance()->getVal(DConfig::BATCH_SIZE);
5151
do {
52-
$oF = new OrderFilter(Hash::HASH_ID, "ASC LIMIT $limit,$size");
52+
$oF = new OrderFilter(Hash::HASH_ID, "ASC LIMIT $size OFFSET $limit");
5353
$qF1 = new QueryFilter(Hash::HASHLIST_ID, $hashlist->getId(), "=");
5454
$qF2 = new QueryFilter(Hash::IS_CRACKED, 1, "=");
5555
$current = Factory::getHashFactory()->filter([Factory::FILTER => [$qF1, $qF2], Factory::ORDER => $oF]);
@@ -68,4 +68,4 @@
6868
} while (sizeof($current) > 0);
6969
}
7070
break;
71-
}
71+
}

src/getHashlist.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
$limit = 0;
5858
$size = SConfig::getInstance()->getVal(DConfig::BATCH_SIZE);
5959
do {
60-
$oF = new OrderFilter(Hash::HASH_ID, "ASC LIMIT $limit,$size");
60+
$oF = new OrderFilter(Hash::HASH_ID, "ASC LIMIT $size OFFSET $limit");
6161
$qF1 = new QueryFilter(Hash::HASHLIST_ID, $hashlist->getId(), "=");
6262
$qF2 = new QueryFilter(Hash::IS_CRACKED, 0, "=");
6363
if ($brain) {
@@ -102,4 +102,4 @@
102102

103103
if ($count == 0) {
104104
die("No hashes are available to crack!");
105-
}
105+
}

src/hashes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
UI::add('previousPage', $previousPage);
196196
UI::add('currentPage', $currentPage);
197197

198-
$oF = new OrderFilter($hashFactory->getNullObject()->getPrimaryKey(), "ASC LIMIT " . (SConfig::getInstance()->getVal(DConfig::HASHES_PER_PAGE) * $currentPage) . ", " . SConfig::getInstance()->getVal(DConfig::HASHES_PER_PAGE));
198+
$oF = new OrderFilter($hashFactory->getNullObject()->getPrimaryKey(), "ASC LIMIT " . SConfig::getInstance()->getVal(DConfig::HASHES_PER_PAGE)) . " OFFSET " . (SConfig::getInstance()->getVal(DConfig::HASHES_PER_PAGE) * $currentPage);
199199
$hashes = $hashFactory->filter([Factory::FILTER => $queryFilters, Factory::ORDER => $oF]);
200200

201201
if (isset($_GET['crackpos']) && $_GET['crackpos'] == 'true') {

src/inc/utils/HashlistUtils.class.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use DBA\QueryFilter;
55
use DBA\ContainFilter;
66
use DBA\OrderFilter;
7+
use DBA\LimitFilter;
78
use DBA\Hashlist;
89
use DBA\HashlistHashlist;
910
use DBA\HashBinary;
@@ -198,8 +199,9 @@ public static function createWordlists($hashlistId, $user) {
198199
$size = $hashFactory->countFilter([Factory::FILTER => [$qF1, $qF2]]);
199200
for ($x = 0; $x * $pagingSize < $size; $x++) {
200201
$buffer = "";
201-
$oF = new OrderFilter(Hash::HASH_ID, "ASC LIMIT " . ($x * $pagingSize) . ", $pagingSize");
202-
$hashes = $hashFactory->filter([Factory::FILTER => [$qF1, $qF2], Factory::ORDER => $oF]);
202+
$oF = new OrderFilter(Hash::HASH_ID, "ASC");
203+
$lF = new LimitFilter($pagingSize, $x * $pagingSize);
204+
$hashes = $hashFactory->filter([Factory::FILTER => [$qF1, $qF2], Factory::ORDER => $oF, Factory::LIMIT => $lF]);
203205
foreach ($hashes as $hash) {
204206
$plain = $hash->getPlaintext();
205207
if (strlen($plain) >= 8 && substr($plain, 0, 5) == "\$HEX[" && substr($plain, strlen($plain) - 1, 1) == "]") {
@@ -714,8 +716,9 @@ public static function export($hashlistId, $user) {
714716
$separator = SConfig::getInstance()->getVal(DConfig::FIELD_SEPARATOR);
715717
$numEntries = 0;
716718
for ($x = 0; $x * $pagingSize < $count; $x++) {
717-
$oF = new OrderFilter($orderObject, "ASC LIMIT " . ($x * $pagingSize) . ",$pagingSize");
718-
$entries = $factory->filter([Factory::FILTER => [$qF1, $qF2], Factory::ORDER => $oF]);
719+
$oF = new OrderFilter($orderObject, "ASC");
720+
$lF = new LimitFilter($pagingSize, $x * $pagingSize);
721+
$entries = $factory->filter([Factory::FILTER => [$qF1, $qF2], Factory::ORDER => $oF, Factory::LIMIT => $lF]);
719722
$buffer = "";
720723
foreach ($entries as $entry) {
721724
switch ($format->getFormat()) {
@@ -1103,8 +1106,9 @@ public static function leftlist($hashlistId, $user) {
11031106
}
11041107
$numEntries = 0;
11051108
for ($x = 0; $x * $pagingSize < $count; $x++) {
1106-
$oF = new OrderFilter(Hash::HASH_ID, "ASC LIMIT " . ($x * $pagingSize) . ",$pagingSize");
1107-
$entries = Factory::getHashFactory()->filter([Factory::FILTER => [$qF1, $qF2], Factory::ORDER => $oF]);
1109+
$oF = new OrderFilter(Hash::HASH_ID, "ASC");
1110+
$lF = new LimitFilter($pagingSize, $x * $pagingSize);
1111+
$entries = Factory::getHashFactory()->filter([Factory::FILTER => [$qF1, $qF2], Factory::ORDER => $oF, Factory::LIMIT => $lF]);
11081112
$buffer = "";
11091113
foreach ($entries as $entry) {
11101114
$buffer .= $entry->getHash();

src/tasks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
}
258258
UI::add('page', $page);
259259
$limit = $page * $chunkPageSize;
260-
$oFp = new OrderFilter(Chunk::SOLVE_TIME, "DESC LIMIT $limit, $chunkPageSize", Factory::getChunkFactory());
260+
$oFp = new OrderFilter(Chunk::SOLVE_TIME, "DESC LIMIT $chunkPageSize OFFSET $limit", Factory::getChunkFactory());
261261
UI::add('chunksPageTitle', "All chunks (page " . ($page + 1) . ")");
262262

263263
$qF = new QueryFilter(Chunk::TASK_ID, $task->getId(), "=");

0 commit comments

Comments
 (0)