Skip to content

Commit

Permalink
Dim/type change cach invalidation (#391)
Browse files Browse the repository at this point in the history
* feat: handles changing an element type in revit via the edit type dialog

looks for any types in the modified object list and adds all objects that have that type as modified

* feat: minor cleanup

* feat: naming, comments

* fix: minor linq changes

---------

Co-authored-by: Oğuzhan Koral <[email protected]>
  • Loading branch information
didimitrie and oguzhankoral authored Dec 3, 2024
1 parent 1ba3f89 commit c2bafc6
Showing 1 changed file with 23 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,32 @@ private async Task RunExpirationChecks()
}

var objUniqueIds = new List<string>();
var changedIds = ChangedObjectIds.Keys.ToList();

// Handling type changes: if an element's type is changed, we need to mark as changed all objects that have that type.
// Step 1: get any changed types
var elementTypeIdsList = changedIds
.Select(e => doc.GetElement(e))
.OfType<ElementType>()
.Select(el => el.Id)
.ToArray();

// Step 2: Find all elements of the changed types, and add them to the changed ids list.
if (elementTypeIdsList.Length != 0)
{
using var collector = new FilteredElementCollector(doc);
var collectorElements = collector
.WhereElementIsNotElementType()
.Where(e => elementTypeIdsList.Contains(e.GetTypeId()));
foreach (var elm in collectorElements)
{
changedIds.Add(elm.Id);
}
}

foreach (var sender in senders)
{
// if (sender.SendFilter is null) // NOTE: RunExpirationChecks sometimes triggered unnecessarily before send and, we didn't set up yet IdMap, if so we do not need to deal with it
// {
// continue;
// }

foreach (var changedElementId in ChangedObjectIds.Keys)
foreach (var changedElementId in changedIds)
{
if (sender.SendFilter?.IdMap?.TryGetValue(changedElementId.ToString(), out var id) ?? false)
{
Expand All @@ -368,21 +385,6 @@ private async Task RunExpirationChecks()
}
}

// foreach (var changedElementId in ChangedObjectIds.Keys.ToArray())
// {
// foreach (var sender in senders)
// {
// if (sender.SendFilter.NotNull().IdMap is null)
// {
// continue;
// }
// if (sender.SendFilter.NotNull().IdMap.NotNull().ContainsKey(changedElementId.ToString()))
// {
// objUniqueIds.Add(sender.SendFilter.NotNull().IdMap.NotNull()[changedElementId.ToString()]);
// }
// }
// }

var unpackedObjectIds = _elementUnpacker.GetUnpackedElementIds(objUniqueIds);
_sendConversionCache.EvictObjects(unpackedObjectIds);

Expand Down

0 comments on commit c2bafc6

Please sign in to comment.