diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/storage_lmdb.cpp | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index bd9bdce..851fe36 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -584,22 +584,8 @@ int DataStore::NamedDatabase::findAllInRange(const QByteArray &lowerBound, const | |||
584 | lastKey = idealLastKey, currentKey; | 584 | lastKey = idealLastKey, currentKey; |
585 | MDB_val reference; | 585 | MDB_val reference; |
586 | 586 | ||
587 | // Find the last key past the range | ||
588 | int rc = mdb_cursor_get(cursor, &lastKey, &reference, MDB_SET_RANGE); | ||
589 | |||
590 | // If only equal, move forward one spot | ||
591 | if (rc == MDB_SUCCESS && mdb_cmp(d->transaction, d->dbi, &lastKey, &idealLastKey) == 0) { | ||
592 | rc = mdb_cursor_get(cursor, &lastKey, &reference, MDB_NEXT); | ||
593 | } | ||
594 | |||
595 | bool untilEnd = false; | ||
596 | if (rc != MDB_SUCCESS) { | ||
597 | // Nothing is greater than the upper bound, meaning search until the end | ||
598 | untilEnd = true; | ||
599 | } | ||
600 | |||
601 | // Find the first key in the range | 587 | // Find the first key in the range |
602 | rc = mdb_cursor_get(cursor, &firstKey, &reference, MDB_SET_RANGE); | 588 | int rc = mdb_cursor_get(cursor, &firstKey, &reference, MDB_SET_RANGE); |
603 | 589 | ||
604 | if (rc != MDB_SUCCESS) { | 590 | if (rc != MDB_SUCCESS) { |
605 | // Nothing is greater or equal than the lower bound, meaning no result | 591 | // Nothing is greater or equal than the lower bound, meaning no result |
@@ -608,16 +594,17 @@ int DataStore::NamedDatabase::findAllInRange(const QByteArray &lowerBound, const | |||
608 | 594 | ||
609 | currentKey = firstKey; | 595 | currentKey = firstKey; |
610 | 596 | ||
611 | do { | 597 | // If already bigger than the upper bound |
612 | // If we have a stopping point and this is the stopping point | 598 | if (mdb_cmp(d->transaction, d->dbi, ¤tKey, &idealLastKey) > 0) { |
613 | if (!untilEnd && mdb_cmp(d->transaction, d->dbi, ¤tKey, &lastKey) == 0) { | 599 | return 0; |
614 | break; | 600 | } |
615 | } | ||
616 | 601 | ||
602 | do { | ||
617 | const auto currentBAKey = QByteArray::fromRawData((char *)currentKey.mv_data, currentKey.mv_size); | 603 | const auto currentBAKey = QByteArray::fromRawData((char *)currentKey.mv_data, currentKey.mv_size); |
618 | const auto currentBAValue = QByteArray::fromRawData((char *)reference.mv_data, reference.mv_size); | 604 | const auto currentBAValue = QByteArray::fromRawData((char *)reference.mv_data, reference.mv_size); |
619 | resultHandler(currentBAKey, currentBAValue); | 605 | resultHandler(currentBAKey, currentBAValue); |
620 | } while (mdb_cursor_get(cursor, ¤tKey, &reference, MDB_NEXT) == MDB_SUCCESS); | 606 | } while (mdb_cursor_get(cursor, ¤tKey, &reference, MDB_NEXT) == MDB_SUCCESS && |
607 | mdb_cmp(d->transaction, d->dbi, ¤tKey, &idealLastKey) <= 0); | ||
621 | } | 608 | } |
622 | 609 | ||
623 | qint64 DataStore::NamedDatabase::getSize() | 610 | qint64 DataStore::NamedDatabase::getSize() |