• 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

90.59
/src/realm/object-store/impl/object_notifier.cpp
1
////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright 2017 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/object_notifier.hpp>
20

21
#include <realm/object-store/shared_realm.hpp>
22
#include <realm/util/scope_exit.hpp>
23

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

27
ObjectNotifier::ObjectNotifier(std::shared_ptr<Realm> realm, const Obj& obj)
28
    : CollectionNotifier(std::move(realm))
29
    , m_table(obj.get_table())
30
    , m_obj_key(obj.get_key())
31
{
3,181✔
32
    if (m_logger) {
3,181✔
NEW
33
        m_description = obj.get_id();
×
NEW
34
        m_logger->log(util::LogCategory::notification, util::Logger::Level::debug, "Creating ObjectNotifier for %1",
×
NEW
35
                      m_description);
×
NEW
36
    }
×
37
}
3,181✔
38

39
void ObjectNotifier::reattach()
40
{
6,362✔
41
    REALM_ASSERT(m_table);
6,362✔
42
    m_table = transaction().get_table(m_table->get_key());
6,362✔
43
}
6,362✔
44

45
bool ObjectNotifier::do_add_required_change_info(TransactionChangeInfo& info)
46
{
8,783✔
47
    if (!m_table)
8,783✔
48
        return false;
2✔
49

5,266✔
50
    m_info = &info;
8,781✔
51
    info.tables[m_table->get_key()];
8,781✔
52

5,266✔
53
    // When adding or removing a callback the related tables can change due to the way we calculate related tables
5,266✔
54
    // when key path filters are set hence we need to recalculate every time the callbacks are changed.
5,266✔
55
    util::CheckedLockGuard lock(m_callback_mutex);
8,781✔
56
    if (m_did_modify_callbacks) {
8,781✔
57
        update_related_tables(*m_table);
3,182✔
58
    }
3,182✔
59

5,266✔
60
    return true;
8,781✔
61
}
8,781✔
62

63
void ObjectNotifier::run()
64
{
11,962✔
65
    if (!m_table || !m_info)
11,962✔
66
        return;
3,181✔
67
    using namespace std::chrono;
8,781✔
68
    auto t1 = steady_clock::now();
8,781✔
69
    util::ScopeExit cleanup([&]() noexcept {
8,781✔
70
        m_run_time_point = steady_clock::now();
8,781✔
71
        if (m_logger) {
8,781✔
NEW
72
            m_logger->log(util::LogCategory::notification, util::Logger::Level::debug,
×
NEW
73
                          "ObjectNotifier %1 did run in %2 us", m_description,
×
NEW
74
                          duration_cast<microseconds>(m_run_time_point - t1).count());
×
NEW
75
        }
×
76
    });
8,781✔
77

5,266✔
78
    auto it = m_info->tables.find(m_table->get_key());
8,781✔
79
    if (it != m_info->tables.end() && it->second.deletions_contains(m_obj_key)) {
8,781✔
80
        // The object was deleted in this set of changes, so report that and
10✔
81
        // release all of our resources so that we don't do anything further.
10✔
82
        m_change.deletions.add(0);
20✔
83
        m_table = {};
20✔
84
        m_obj_key = {};
20✔
85
        return;
20✔
86
    }
20✔
87

5,256✔
88
    if (!m_change.modifications.contains(0) && any_callbacks_filtered()) {
8,761✔
89
        // If any callback has a key path filter we will check all related tables and if any of them was changed we
39✔
90
        // mark the this object as changed.
39✔
91
        auto object_change_checker = get_object_modification_checker(*m_info, m_table);
78✔
92
        std::vector<ColKey> changed_columns = object_change_checker(m_obj_key);
78✔
93

39✔
94
        if (changed_columns.size() > 0) {
78✔
95
            m_change.modifications.add(0);
36✔
96
            for (auto changed_column : changed_columns) {
42✔
97
                m_change.columns[changed_column.value].add(0);
42✔
98
            }
42✔
99
        }
36✔
100
        if (all_callbacks_filtered()) {
78✔
101
            return;
64✔
102
        }
64✔
103
    }
8,697✔
104

5,224✔
105
    if (it == m_info->tables.end())
8,697✔
106
        // This object's table is not in the map of changed tables held by `m_info`
644✔
107
        // hence no further details have to be checked.
644✔
108
        return;
1,284✔
109

4,580✔
110
    const auto& change = it->second;
7,413✔
111

4,580✔
112
    auto column_modifications = change.get_columns_modified(m_obj_key);
7,413✔
113
    if (!column_modifications)
7,413✔
114
        return;
1,342✔
115

3,782✔
116
    // Finally we add all changes to `m_change` which is later used to notify about the changed columns.
3,782✔
117
    m_change.modifications.add(0);
6,071✔
118
    for (auto col : *column_modifications) {
6,423✔
119
        m_change.columns[col.value].add(0);
6,423✔
120
    }
6,423✔
121
}
6,071✔
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