Skip to content

Commit

Permalink
Merge pull request 'bugfix/tracker-concurrency' (#107) from bugfix/tr…
Browse files Browse the repository at this point in the history
…acker-concurrency into hotfix/v3.0.1
  • Loading branch information
pavelbannov committed Nov 27, 2024
2 parents 9a9a125 + 0a56038 commit 2b698d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 29 deletions.
9 changes: 1 addition & 8 deletions common/ASC.Common/Caching/Protobuf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,7 @@ public static T Deserialize<T>(byte[] data)

public static T Deserialize<T>(ReadOnlySpan<byte> data)
{
try
{
return Serializer.Deserialize<T>(data);
}
catch (ArgumentException) // concurrency handling
{
return Serializer.Deserialize<T>(data);
}
return Serializer.Deserialize<T>(data);
}
}

Expand Down
37 changes: 16 additions & 21 deletions products/ASC.Files/Core/Utils/FileTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public async Task<bool> ProlongEditingAsync<T>(T fileId, Guid tabId, Guid userId
}
else
{
tracker.EditingBy.Add(tabId,
tracker.EditingBy.TryAdd(tabId,
new TrackInfo
{
UserId = userId,
Expand Down Expand Up @@ -120,7 +120,7 @@ public async Task RemoveAsync<T>(T fileId, Guid tabId = default, Guid userId = d
{
if (tabId != Guid.Empty)
{
tracker.EditingBy.Remove(tabId);
tracker.EditingBy.TryRemove(tabId, out _);
await SetTrackerAsync(fileId, tracker);

return;
Expand All @@ -132,7 +132,7 @@ public async Task RemoveAsync<T>(T fileId, Guid tabId = default, Guid userId = d

foreach (var editTab in listForRemove)
{
tracker.EditingBy.Remove(editTab.Key);
tracker.EditingBy.TryRemove(editTab.Key, out _);
}

await SetTrackerAsync(fileId, tracker);
Expand All @@ -155,10 +155,10 @@ public async Task<bool> IsEditingAsync<T>(T fileId)

foreach (var editTab in listForRemove)
{
tracker.EditingBy.Remove(editTab.Key);
tracker.EditingBy.TryRemove(editTab.Key, out _);
}

if (tracker.EditingBy.Count == 0)
if (tracker.EditingBy.IsEmpty)
{
await RemoveTrackerAsync(fileId);

Expand Down Expand Up @@ -323,27 +323,22 @@ public record FileTrackerNotify
public record FileTracker
{
[ProtoMember(1)]
public Dictionary<Guid, TrackInfo> EditingBy { get; set; }
public ConcurrentDictionary<Guid, TrackInfo> EditingBy { get; set; }

public FileTracker() { }

internal FileTracker(Guid tabId, Guid userId, bool newScheme, bool editingAlone, int tenantId, string baseUri, string token = null)
{
EditingBy = new Dictionary<Guid, TrackInfo>
{
{
tabId,
new TrackInfo
{
UserId = userId,
NewScheme = newScheme,
EditingAlone = editingAlone,
TenantId = tenantId,
BaseUri = baseUri,
Token = token
}
}
};
EditingBy = new ConcurrentDictionary<Guid, TrackInfo>();
EditingBy.TryAdd(tabId, new TrackInfo
{
UserId = userId,
NewScheme = newScheme,
EditingAlone = editingAlone,
TenantId = tenantId,
BaseUri = baseUri,
Token = token
});
}

[ProtoContract]
Expand Down

0 comments on commit 2b698d9

Please sign in to comment.