Fix tracking of modifications after linkview moves

This commit is contained in:
Thomas Goyne 2016-03-21 15:02:53 -07:00
parent a0b16305c9
commit 7a74a22558
4 changed files with 40 additions and 5 deletions

View File

@ -94,6 +94,8 @@ void CollectionChangeBuilder::merge(CollectionChangeBuilder&& c)
return old.to == m.from;
});
if (it != c.moves.end()) {
if (modifications.contains(it->from))
c.modifications.add(it->to);
old.to = it->to;
*it = c.moves.back();
c.moves.pop_back();

View File

@ -96,17 +96,20 @@ void ListNotifier::run()
return;
}
m_change.moves.erase(remove_if(begin(m_change.moves), end(m_change.moves),
[&](auto move) { return m_change.modifications.contains(move.to); }),
end(m_change.moves));
for (size_t i = 0; i < m_lv->size(); ++i) {
if (m_change.insertions.contains(i) || m_change.modifications.contains(i))
if (m_change.modifications.contains(i))
continue;
if (m_info->row_did_change(m_lv->get_target_table(), m_lv->get(i).get_index()))
m_change.modifications.add(i);
}
for (auto const& move : m_change.moves) {
if (m_change.modifications.contains(move.to))
continue;
if (m_info->row_did_change(m_lv->get_target_table(), m_lv->get(move.to).get_index()))
m_change.modifications.add(move.to);
}
m_prev_size = m_lv->size();
}

View File

@ -861,6 +861,14 @@ TEST_CASE("[collection_change] merge()") {
REQUIRE_MOVES(c, {1, 3});
}
SECTION("updates the row modified for chained moves") {
c = {{}, {}, {1}, {}};
c.merge({{}, {}, {}, {{1, 3}}});
c.merge({{}, {}, {}, {{3, 5}}});
REQUIRE_INDICES(c.modifications, 5);
REQUIRE_MOVES(c, {1, 5});
}
SECTION("updates the row inserted for moves of previously new rows") {
c = {{}, {1}, {}, {}};
c.merge({{}, {}, {}, {{1, 3}}});

View File

@ -219,6 +219,28 @@ TEST_CASE("list") {
REQUIRE_INDICES(changes[i].modifications, 2);
}
}
SECTION("modifications are reported for rows that are moved and then moved back in a second transaction") {
auto token = require_change();
r->begin_transaction();
lv->get(5).set_int(0, 10);
lv->get(1).set_int(0, 10);
lv->move(5, 8);
lv->move(1, 2);
r->commit_transaction();
coordinator.on_change();
write([&]{
lv->move(8, 5);
});
REQUIRE_INDICES(change.deletions, 1);
REQUIRE_INDICES(change.insertions, 2);
REQUIRE_INDICES(change.modifications, 5);
REQUIRE_MOVES(change, {1, 2});
}
}
SECTION("sorted add_notification_block()") {