Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Orm/Xtensive.Orm/Orm/EntitySetBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -808,11 +808,10 @@ internal void ExceptWith<TElement>(IEnumerable<TElement> other)

#region Private / internal members

internal EntitySetState UpdateState(IEnumerable<Key> items, bool isFullyLoaded)
internal EntitySetState UpdateState(IReadOnlyList<Key> items, bool isFullyLoaded)
{
EnsureOwnerIsNotRemoved();
var itemList = items.ToList();
State.Update(itemList, isFullyLoaded ? (long?) itemList.Count : null);
State.Update(items, isFullyLoaded ? items.Count : null);
State.IsLoaded = true;
Session.NotifyEntitySetCached(this);
return State;
Expand Down
42 changes: 11 additions & 31 deletions Orm/Xtensive.Orm/Orm/Internals/Prefetch/EntitySetTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,49 +90,29 @@ public void UpdateCache()
return;
}

var areToNotifyAboutKeys = !manager.Owner.Session.Domain.Model
var managerOwner = manager.Owner;
var areToNotifyAboutKeys = !managerOwner.Session.Domain.Model
.Types[referencingFieldDescriptor.Field.ItemType].IsLeaf;
var reader = manager.Owner.Session.Domain.EntityDataReader;
var records = reader.Read(itemsQueryTask.Result, QueryProvider.Header, manager.Owner.Session);
var reader = managerOwner.Session.Domain.EntityDataReader;
var records = reader.Read(itemsQueryTask.Result, QueryProvider.Header, managerOwner.Session);
var entityKeys = new List<Key>(itemsQueryTask.Result.Count);
var association = ReferencingField.Associations[^1];
var auxEntities = (association.AuxiliaryType != null)
? new List<(Key, Tuple)>(itemsQueryTask.Result.Count)
: null;

foreach (var record in records) {
for (var i = 0; i < record.Count; i++) {
var key = record.GetKey(i);
if (key is null) {
continue;
}
var tuple = record.GetTuple(i);
if (tuple == null) {
continue;
}
if (association.AuxiliaryType != null) {
if (i == 0) {
auxEntities.Add((key, tuple));
}
else {
manager.SaveStrongReference(manager.Owner.UpdateState(key, tuple));
entityKeys.Add(key);
if (areToNotifyAboutKeys) {
referencingFieldDescriptor.NotifySubscriber(ownerKey, key);
}
}
}
else {
manager.SaveStrongReference(manager.Owner.UpdateState(key, tuple));
for (int i = 0, count = record.Count; i < count; i++) {
if (record.GetKey(i) is { } key
&& record.GetTuple(i) is { } tuple
&& (association.AuxiliaryType == null || i != 0)) {
manager.SaveStrongReference(managerOwner.UpdateState(key, tuple));
entityKeys.Add(key);
if (areToNotifyAboutKeys) {
referencingFieldDescriptor.NotifySubscriber(ownerKey, key);
}
}
}
}
var updatedState = manager.Owner.UpdateState(ownerKey, ReferencingField,
ItemCountLimit == null || entityKeys.Count < ItemCountLimit, entityKeys, auxEntities);
var updatedState = managerOwner.UpdateState(ownerKey, ReferencingField,
ItemCountLimit == null || entityKeys.Count < ItemCountLimit, entityKeys);
if (updatedState != null) {
updatedState.SetLastManualPrefetchId(referencingFieldDescriptor.PrefetchOperationId);
}
Expand Down
4 changes: 2 additions & 2 deletions Orm/Xtensive.Orm/Orm/Providers/ChainingSessionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ public override void FetchEntitySet(Key ownerKey, FieldInfo field, int? itemCoun
}

internal override EntitySetState UpdateState(Key key, FieldInfo fieldInfo,
bool isFullyLoaded, List<Key> entities, List<(Key, Tuple)> auxEntities)
bool isFullyLoaded, IReadOnlyList<Key> entities)
Comment thread
snaumenko-st marked this conversation as resolved.
Resolved
{
return ChainedHandler.UpdateState(key, fieldInfo, isFullyLoaded, entities, auxEntities);
return ChainedHandler.UpdateState(key, fieldInfo, isFullyLoaded, entities);
}

internal override EntityState UpdateState(Key key, Tuple tuple)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal virtual EntityState UpdateState(Key key, Tuple tuple)
}

internal virtual EntitySetState UpdateState(Key key, FieldInfo fieldInfo,
bool isFullyLoaded, List<Key> entityKeys, List<(Key, Tuple)> auxEntities)
bool isFullyLoaded, IReadOnlyList<Key> entityKeys)
{
return Session.UpdateStateInCache(key, fieldInfo, entityKeys, isFullyLoaded);
}
Expand Down
2 changes: 1 addition & 1 deletion Orm/Xtensive.Orm/Orm/Session.Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ internal EntityState UpdateStateInCache(Key key, Tuple tuple)
return UpdateStateInCache(key, tuple, false);
}

internal EntitySetState UpdateStateInCache(Key key, FieldInfo fieldInfo, IEnumerable<Key> entityKeys,
internal EntitySetState UpdateStateInCache(Key key, FieldInfo fieldInfo, IReadOnlyList<Key> entityKeys,
bool isFullyLoaded)
{
var entityState = EntityStateCache[key, true];
Expand Down
Loading