Fix prev/next behaviour on database iterator

Fixes issue with apparent duplicated tracks in the infinite list
custom
ailurux 11 months ago
parent 2ff8eac022
commit 9dbcd6a5c8
  1. 7
      src/tangara/database/database.cpp
  2. 4
      src/tangara/lua/lua_database.cpp

@ -704,9 +704,8 @@ Iterator::Iterator(std::shared_ptr<Database> db, const IndexKey::Header& header)
key_ = {
.prefix = {prefix.data(), prefix.size(), &memory::kSpiRamResource},
.key = {},
.offset = 0,
.offset = -1,
};
iterate(key_);
}
auto Iterator::value() const -> const std::optional<Record>& {
@ -715,7 +714,11 @@ auto Iterator::value() const -> const std::optional<Record>& {
auto Iterator::next() -> void {
SearchKey new_key = key_;
if (new_key.offset == -1) {
new_key.offset = 0;
} else {
new_key.offset = 1;
}
iterate(new_key);
}

@ -162,7 +162,7 @@ static auto push_iterator(lua_State* state,
static auto db_iterate_prev(lua_State* state) -> int {
database::Iterator* it = db_check_iterator(state, 1);
std::optional<database::Record> res = (*it)--;
std::optional<database::Record> res = --(*it);
if (res) {
push_lua_record(state, *res);
@ -175,7 +175,7 @@ static auto db_iterate_prev(lua_State* state) -> int {
static auto db_iterate(lua_State* state) -> int {
database::Iterator* it = db_check_iterator(state, 1);
std::optional<database::Record> res = (*it)++;
std::optional<database::Record> res = ++(*it);
if (res) {
push_lua_record(state, *res);

Loading…
Cancel
Save