• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

realm / realm-core / nicola.cabiddu_1042

27 Sep 2023 06:04PM UTC coverage: 91.085% (-1.8%) from 92.915%
nicola.cabiddu_1042

Pull #6766

Evergreen

nicola-cab
Fix logic for dictionaries
Pull Request #6766: Client Reset for collections in mixed / nested collections

97276 of 178892 branches covered (0.0%)

1994 of 2029 new or added lines in 7 files covered. (98.28%)

4556 existing lines in 112 files now uncovered.

237059 of 260260 relevant lines covered (91.09%)

6321099.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.67
/src/realm/object-store/impl/list_notifier.cpp
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2016 Realm Inc.
4
//
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing, software
12
// distributed under the License is distributed on an "AS IS" BASIS,
13
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
// See the License for the specific language governing permissions and
15
// limitations under the License.
16
//
17
////////////////////////////////////////////////////////////////////////////
18

19
#include <realm/object-store/impl/list_notifier.hpp>
20

21
#include <realm/object-store/list.hpp>
22

23
#include <realm/transaction.hpp>
24

25
using namespace realm;
26
using namespace realm::_impl;
27

28
ListNotifier::ListNotifier(std::shared_ptr<Realm> realm, CollectionBase const& list, PropertyType type)
29
    : CollectionNotifier(std::move(realm))
30
    , m_type(type)
31
    , m_prev_size(list.size())
32
{
1,184✔
33
    attach(list);
1,184✔
34
}
1,184✔
35

36
void ListNotifier::release_data() noexcept
37
{
1,184✔
38
    m_list = {};
1,184✔
39
    CollectionNotifier::release_data();
1,184✔
40
}
1,184✔
41

42
void ListNotifier::reattach()
43
{
2,364✔
44
    REALM_ASSERT(m_list);
2,364✔
45
    attach(*m_list);
2,364✔
46
}
2,364✔
47

48
void ListNotifier::attach(CollectionBase const& src)
49
{
3,548✔
50
    auto& tr = transaction();
3,548✔
51
    if (auto obj = tr.get_table(src.get_table()->get_key())->try_get_object(src.get_owner_key())) {
3,548✔
52
        auto path = src.get_stable_path();
3,464✔
53
        m_list = std::static_pointer_cast<CollectionBase>(obj.get_collection_by_stable_path(path));
3,464✔
54
    }
3,464✔
55
    else {
84✔
56
        m_list = nullptr;
84✔
57
    }
84✔
58
}
3,548✔
59

60
bool ListNotifier::do_add_required_change_info(TransactionChangeInfo& info)
61
{
1,802✔
62
    if (!m_list || !m_list->is_attached())
1,802✔
63
        return false; // origin row was deleted after the notification was added
98✔
64

852✔
65
    info.collections.push_back(
1,704✔
66
        {m_list->get_table()->get_key(), m_list->get_owner_key(), m_list->get_stable_path(), &m_change});
1,704✔
67

852✔
68
    m_info = &info;
1,704✔
69

852✔
70
    // When adding or removing a callback, the related tables can change due to the way we calculate related tables
852✔
71
    // when key path filters are set, hence we need to recalculate every time the callbacks are changed.
852✔
72
    // We only need to do this for lists that link to other lists. Lists of primitives cannot have related tables.
852✔
73
    util::CheckedLockGuard lock(m_callback_mutex);
1,704✔
74
    if (m_did_modify_callbacks && m_type == PropertyType::Object) {
1,704✔
75
        update_related_tables(*m_list->get_table());
232✔
76
    }
232✔
77

852✔
78
    return true;
1,704✔
79
}
1,704✔
80

81
void ListNotifier::run()
82
{
2,816✔
83
    if (!m_list || !m_list->is_attached()) {
2,816✔
84
        // List was deleted, so report all of the rows being removed if this is
194✔
85
        // the first run after that
194✔
86
        if (m_prev_size) {
388✔
87
            m_change.deletions.set(m_prev_size);
242✔
88
            m_prev_size = 0;
242✔
89
        }
242✔
90
        else {
146✔
91
            m_change = {};
146✔
92
        }
146✔
93
        report_collection_root_is_deleted();
388✔
94
        return;
388✔
95
    }
388✔
96

1,214✔
97
    m_prev_size = m_list->size();
2,428✔
98

1,214✔
99
    if (m_info && m_type == PropertyType::Object) {
2,428✔
100
        auto object_did_change = get_modification_checker(*m_info, m_list->get_target_table());
320✔
101
        for (size_t i = 0; i < m_prev_size; ++i) {
1,638✔
102
            if (m_change.modifications.contains(i))
1,318✔
103
                continue;
52✔
104
            auto m = m_list->get_any(i);
1,266✔
105
            if (!m.is_null() && object_did_change(m.get<ObjKey>()))
1,266✔
106
                m_change.modifications.add(i);
62✔
107
        }
1,266✔
108

160✔
109
        for (auto const& move : m_change.moves) {
166✔
110
            if (m_change.modifications.contains(move.to))
12✔
111
                continue;
8✔
112
            if (object_did_change(m_list->get_any(move.to).get<ObjKey>()))
4✔
UNCOV
113
                m_change.modifications.add(move.to);
×
114
        }
4✔
115
    }
320✔
116
}
2,428✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc