@@ -396,40 +396,24 @@ void CollectionKeyPathChangeChecker::find_changed_columns(std::vector<ColKey>& c
396
396
397
397
if (depth >= key_path.size ()) {
398
398
// We've reached the end of the key path.
399
-
400
- // For the special case of having a backlink at the end of a key path we need to check this level too.
401
- // Modifications to a backlink are found via the insertions on the origin table (which we are in right
402
- // now).
403
- auto last_key_path_element = key_path[key_path.size () - 1 ];
404
- auto last_column_key = last_key_path_element.second ;
405
- if (last_column_key.get_type () == col_type_BackLink) {
406
- auto iterator = m_info.tables .find (table.get_key ());
407
- auto table_has_changed = [iterator] {
408
- return !iterator->second .insertions_empty () || !iterator->second .modifications_empty () ||
409
- !iterator->second .deletions_empty ();
410
- };
411
- if (iterator != m_info.tables .end () && table_has_changed ()) {
412
- ColKey root_column_key = key_path[0 ].second ;
413
- changed_columns.push_back (root_column_key);
414
- }
415
- }
416
-
417
399
return ;
418
400
}
419
401
420
402
auto [table_key, column_key] = key_path.at (depth);
421
403
422
404
// Check for a change on the current depth level.
423
405
auto iterator = m_info.tables .find (table_key);
424
- if (iterator != m_info.tables .end () && (iterator->second .modifications_contains (object_key, {column_key}) ||
425
- iterator->second .insertions_contains (object_key))) {
426
- // If an object linked to the root object was changed we only mark the
427
- // property of the root objects as changed.
428
- // This is also the reason why we can return right after doing so because we would only mark the same root
429
- // property again in case we find another change deeper down the same path.
430
- auto root_column_key = key_path[0 ].second ;
431
- changed_columns.push_back (root_column_key);
432
- return ;
406
+ if (iterator != m_info.tables .end ()) {
407
+ auto & changes = iterator->second ;
408
+ if (changes.modifications_contains (object_key, {column_key}) || changes.insertions_contains (object_key)) {
409
+ // If an object linked to the root object was changed we only mark the
410
+ // property of the root objects as changed.
411
+ // This is also the reason why we can return right after doing so because we would only mark the same root
412
+ // property again in case we find another change deeper down the same path.
413
+ auto root_column_key = key_path[0 ].second ;
414
+ changed_columns.push_back (root_column_key);
415
+ return ;
416
+ }
433
417
}
434
418
435
419
// Only continue for any kind of link.
@@ -448,11 +432,12 @@ void CollectionKeyPathChangeChecker::find_changed_columns(std::vector<ColKey>& c
448
432
auto target_table_key = mixed_object.get_link ().get_table_key ();
449
433
Group* group = table.get_parent_group ();
450
434
auto target_table = group->get_table (target_table_key);
451
- find_changed_columns (changed_columns, key_path, depth + 1 , *target_table, object_key);
435
+ find_changed_columns (changed_columns, key_path, depth, *target_table, object_key);
452
436
}
453
437
};
454
438
455
439
// Advance one level deeper into the key path.
440
+ depth++;
456
441
auto object = table.get_object (object_key);
457
442
if (column_key.is_list ()) {
458
443
if (column_type == col_type_Mixed) {
@@ -468,7 +453,7 @@ void CollectionKeyPathChangeChecker::find_changed_columns(std::vector<ColKey>& c
468
453
auto target_table = table.get_link_target (column_key);
469
454
for (size_t i = 0 ; i < list.size (); i++) {
470
455
auto target_object = list.get (i);
471
- find_changed_columns (changed_columns, key_path, depth + 1 , *target_table, target_object);
456
+ find_changed_columns (changed_columns, key_path, depth, *target_table, target_object);
472
457
}
473
458
}
474
459
}
@@ -484,7 +469,7 @@ void CollectionKeyPathChangeChecker::find_changed_columns(std::vector<ColKey>& c
484
469
auto set = object.get_linkset (column_key);
485
470
auto target_table = table.get_link_target (column_key);
486
471
for (auto & target_object : set) {
487
- find_changed_columns (changed_columns, key_path, depth + 1 , *target_table, target_object);
472
+ find_changed_columns (changed_columns, key_path, depth, *target_table, target_object);
488
473
}
489
474
}
490
475
}
@@ -505,7 +490,7 @@ void CollectionKeyPathChangeChecker::find_changed_columns(std::vector<ColKey>& c
505
490
return ;
506
491
}
507
492
auto target_table = table.get_link_target (column_key);
508
- find_changed_columns (changed_columns, key_path, depth + 1 , *target_table, target_object);
493
+ find_changed_columns (changed_columns, key_path, depth, *target_table, target_object);
509
494
}
510
495
else if (column_type == col_type_BackLink) {
511
496
// A backlink can have multiple origin objects. We need to iterate over all of them.
@@ -514,7 +499,23 @@ void CollectionKeyPathChangeChecker::find_changed_columns(std::vector<ColKey>& c
514
499
size_t backlink_count = object.get_backlink_count (*origin_table, origin_column_key);
515
500
for (size_t i = 0 ; i < backlink_count; i++) {
516
501
auto origin_object = object.get_backlink (*origin_table, origin_column_key, i);
517
- find_changed_columns (changed_columns, key_path, depth + 1 , *origin_table, origin_object);
502
+ if (depth == key_path.size ()) {
503
+ // For the special case of having a backlink at the end of a key path we need to check this level too.
504
+ // Modifications to a backlink are found via the insertions on the origin table (which we are in right
505
+ // now).
506
+ auto iterator = m_info.tables .find (origin_table->get_key ());
507
+ if (iterator != m_info.tables .end ()) {
508
+ auto & changes = iterator->second ;
509
+ if (changes.modifications_contains (origin_object, {origin_column_key}) ||
510
+ changes.insertions_contains (origin_object)) {
511
+ ColKey root_column_key = key_path[0 ].second ;
512
+ changed_columns.push_back (root_column_key);
513
+ }
514
+ }
515
+ }
516
+ else {
517
+ find_changed_columns (changed_columns, key_path, depth, *origin_table, origin_object);
518
+ }
518
519
}
519
520
}
520
521
else {
0 commit comments