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

realm / realm-core / github_pull_request_281750

30 Oct 2023 03:37PM UTC coverage: 90.528% (-1.0%) from 91.571%
github_pull_request_281750

Pull #6073

Evergreen

jedelbo
Log free space and history sizes when opening file
Pull Request #6073: Merge next-major

95488 of 175952 branches covered (0.0%)

8973 of 12277 new or added lines in 149 files covered. (73.09%)

622 existing lines in 51 files now uncovered.

233503 of 257934 relevant lines covered (90.53%)

6533720.56 hits per line

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

87.23
/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
#include <realm/util/scope_exit.hpp>
25

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

29
ListNotifier::ListNotifier(std::shared_ptr<Realm> realm, CollectionBase const& list, PropertyType type)
30
    : CollectionNotifier(std::move(realm))
31
    , m_type(type)
32
    , m_prev_size(list.size())
33
{
1,136✔
34
    attach(list);
1,136✔
35
    if (m_logger) {
1,136✔
NEW
36
        auto path = m_list->get_short_path();
×
NEW
37
        auto prop_name = m_list->get_table()->get_column_name(path[0].get_col_key());
×
NEW
38
        path[0] = PathElement(prop_name);
×
39

NEW
40
        m_description = util::format("%1 %2%3", list.get_collection_type(), m_list->get_obj().get_id(), path);
×
NEW
41
        m_logger->log(util::LogCategory::notification, util::Logger::Level::debug,
×
NEW
42
                      "Creating CollectionNotifier for %1", m_description);
×
NEW
43
    }
×
44
}
1,136✔
45

46
void ListNotifier::release_data() noexcept
47
{
1,136✔
48
    m_list = {};
1,136✔
49
    CollectionNotifier::release_data();
1,136✔
50
}
1,136✔
51

52
void ListNotifier::reattach()
53
{
2,268✔
54
    REALM_ASSERT(m_list);
2,268✔
55
    attach(*m_list);
2,268✔
56
}
2,268✔
57

58
void ListNotifier::attach(CollectionBase const& src)
59
{
3,404✔
60
    auto& tr = transaction();
3,404✔
61
    if (auto obj = tr.get_table(src.get_table()->get_key())->try_get_object(src.get_owner_key())) {
3,404✔
62
        auto path = src.get_stable_path();
3,320✔
63
        m_list = std::static_pointer_cast<CollectionBase>(obj.get_collection_by_stable_path(path));
3,320✔
64
    }
3,320✔
65
    else {
84✔
66
        m_list = nullptr;
84✔
67
    }
84✔
68
}
3,404✔
69

70
bool ListNotifier::do_add_required_change_info(TransactionChangeInfo& info)
71
{
1,754✔
72
    if (!m_list || !m_list->is_attached())
1,754✔
73
        return false; // origin row was deleted after the notification was added
98✔
74

828✔
75
    info.collections.push_back(
1,656✔
76
        {m_list->get_table()->get_key(), m_list->get_owner_key(), m_list->get_stable_path(), &m_change});
1,656✔
77

828✔
78
    m_info = &info;
1,656✔
79

828✔
80
    // When adding or removing a callback, the related tables can change due to the way we calculate related tables
828✔
81
    // when key path filters are set, hence we need to recalculate every time the callbacks are changed.
828✔
82
    // We only need to do this for lists that link to other lists. Lists of primitives cannot have related tables.
828✔
83
    util::CheckedLockGuard lock(m_callback_mutex);
1,656✔
84
    if (m_did_modify_callbacks && m_type == PropertyType::Object) {
1,656✔
85
        update_related_tables(*m_list->get_table());
232✔
86
    }
232✔
87

828✔
88
    return true;
1,656✔
89
}
1,656✔
90

91
void ListNotifier::run()
92
{
2,768✔
93
    using namespace std::chrono;
2,768✔
94
    auto t1 = steady_clock::now();
2,768✔
95
    util::ScopeExit cleanup([&]() noexcept {
2,768✔
96
        m_run_time_point = steady_clock::now();
2,768✔
97
        if (m_logger) {
2,768✔
NEW
98
            m_logger->log(util::LogCategory::notification, util::Logger::Level::debug,
×
NEW
99
                          "ListNotifier %1 did run in %2 us", m_description,
×
NEW
100
                          duration_cast<microseconds>(m_run_time_point - t1).count());
×
NEW
101
        }
×
102
    });
2,768✔
103

1,384✔
104
    if (!m_list || !m_list->is_attached()) {
2,768✔
105
        // List was deleted, so report all of the rows being removed if this is
192✔
106
        // the first run after that
192✔
107
        if (m_prev_size) {
384✔
108
            m_change.deletions.set(m_prev_size);
238✔
109
            m_prev_size = 0;
238✔
110
        }
238✔
111
        else {
146✔
112
            m_change = {};
146✔
113
        }
146✔
114
        report_collection_root_is_deleted();
384✔
115
        return;
384✔
116
    }
384✔
117

1,192✔
118
    m_prev_size = m_list->size();
2,384✔
119

1,192✔
120
    if (m_info && m_type == PropertyType::Object) {
2,384✔
121
        auto object_did_change = get_modification_checker(*m_info, m_list->get_target_table());
320✔
122
        for (size_t i = 0; i < m_prev_size; ++i) {
1,638✔
123
            if (m_change.modifications.contains(i))
1,318✔
124
                continue;
52✔
125
            auto m = m_list->get_any(i);
1,266✔
126
            if (!m.is_null() && object_did_change(m.get<ObjKey>()))
1,266✔
127
                m_change.modifications.add(i);
62✔
128
        }
1,266✔
129

160✔
130
        for (auto const& move : m_change.moves) {
166✔
131
            if (m_change.modifications.contains(move.to))
12✔
132
                continue;
8✔
133
            if (object_did_change(m_list->get_any(move.to).get<ObjKey>()))
4✔
134
                m_change.modifications.add(move.to);
×
135
        }
4✔
136
    }
320✔
137
}
2,384✔
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