Skip to content

Commit

Permalink
Improve tracking of Ids
Browse files Browse the repository at this point in the history
  • Loading branch information
KenitoInc committed Jul 14, 2020
1 parent 7c27ffa commit 902d05a
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/Microsoft.OData.Core/JsonLight/ODataJsonLightBatchReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,9 @@ internal sealed class ODataJsonLightBatchReader : ODataBatchReader
private ODataJsonLightBatchPayloadItemPropertiesCache messagePropertiesCache = null;

/// <summary>
/// Dictionary for keeping track of each request's associated atomic group id, which is null
/// for request that does not belong to atomic group.
/// Collection for keeping track of unique atomic group ids and member request ids.
/// </summary>
private Dictionary<string, string> requestIdToAtomicGroupId = new Dictionary<string, string>();

/// <summary>
/// Dictionary for keeping track of each atomic group's member request id. This is optimization
/// for reversed lookup.
/// </summary>
private Dictionary<string, IList<string>> atomicityGroupIdToRequestId = new Dictionary<string, IList<string>>();
private HashSet<string> requestIds = new HashSet<string>();

/// <summary>
/// Constructor.
Expand Down Expand Up @@ -136,19 +129,14 @@ protected override ODataBatchOperationRequestMessage CreateOperationRequestMessa
string atomicityGroupId = (string)this.messagePropertiesCache.GetPropertyValue(
ODataJsonLightBatchPayloadItemPropertiesCache.PropertyNameAtomicityGroup);

if (id != null && !this.requestIdToAtomicGroupId.ContainsKey(id))
if (id != null)
{
this.requestIdToAtomicGroupId.Add(id, atomicityGroupId);
this.requestIds.Add(id);
}

if (atomicityGroupId != null)
{
if (!this.atomicityGroupIdToRequestId.ContainsKey(atomicityGroupId))
{
this.atomicityGroupIdToRequestId.Add(atomicityGroupId, new List<string>() { id });
}

this.atomicityGroupIdToRequestId[atomicityGroupId].Add(id);
this.requestIds.Add(atomicityGroupId);
}

// dependsOn
Expand Down Expand Up @@ -370,8 +358,8 @@ protected override void ValidateDependsOnIds(string contentId, IEnumerable<strin
// Content-ID cannot be part of dependsOnIds. This is to avoid self referencing.
// The dependsOnId must be an existing request ID or atomicityGroup
if (id == contentId ||
(!this.requestIdToAtomicGroupId.ContainsKey(id) &&
!this.atomicityGroupIdToRequestId.ContainsKey(id)))
(!this.requestIds.Contains(id) &&
!this.requestIds.Contains(id)))
{
throw new ODataException(Strings.ODataBatchReader_DependsOnIdNotFound(id, contentId));
}
Expand Down

0 comments on commit 902d05a

Please sign in to comment.