Skip to content

Commit

Permalink
refactor: update InMemoryStream
Browse files Browse the repository at this point in the history
  • Loading branch information
WeihanLi committed Dec 15, 2024
1 parent 339a0c4 commit 4bc2ca5
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/WeihanLi.Common/Helpers/InMemoryStream.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Weihan Li. All rights reserved.
// Licensed under the Apache license.

using System.Collections.Concurrent;
using System.Runtime.CompilerServices;
using WeihanLi.Common.Models;
Expand Down Expand Up @@ -151,16 +154,28 @@ public Task<IReadOnlyCollection<StreamGroupInfo<T>>> GroupsAsync(CancellationTok

public Task<StreamInfo<T>> InfoAsync(CancellationToken cancellationToken = default)
{
var minMessage = _messages.MinBy(item => item.Id);
var maxMessage = _messages.MaxBy(item => item.Id);
var streamInfo = new StreamInfo<T>
{
MinId = minMessage?.Id ?? default,
MinTimestamp = minMessage?.Timestamp ?? default,
MaxId = maxMessage?.Id ?? default,
MaxTimestamp = maxMessage?.Timestamp ?? default,
MinId = default,

Check warning on line 159 in src/WeihanLi.Common/Helpers/InMemoryStream.cs

View workflow job for this annotation

GitHub Actions / Running tests on ubuntu-latest

Possible null reference assignment.

Check warning on line 159 in src/WeihanLi.Common/Helpers/InMemoryStream.cs

View workflow job for this annotation

GitHub Actions / Running tests on ubuntu-latest

Possible null reference assignment.

Check warning on line 159 in src/WeihanLi.Common/Helpers/InMemoryStream.cs

View workflow job for this annotation

GitHub Actions / Running tests on macOS-latest

Possible null reference assignment.

Check warning on line 159 in src/WeihanLi.Common/Helpers/InMemoryStream.cs

View workflow job for this annotation

GitHub Actions / Running tests on macOS-latest

Possible null reference assignment.

Check warning on line 159 in src/WeihanLi.Common/Helpers/InMemoryStream.cs

View workflow job for this annotation

GitHub Actions / Running tests on windows-latest

Possible null reference assignment.
MinTimestamp = default,
MaxId = default,

Check warning on line 161 in src/WeihanLi.Common/Helpers/InMemoryStream.cs

View workflow job for this annotation

GitHub Actions / Running tests on ubuntu-latest

Possible null reference assignment.

Check warning on line 161 in src/WeihanLi.Common/Helpers/InMemoryStream.cs

View workflow job for this annotation

GitHub Actions / Running tests on ubuntu-latest

Possible null reference assignment.

Check warning on line 161 in src/WeihanLi.Common/Helpers/InMemoryStream.cs

View workflow job for this annotation

GitHub Actions / Running tests on macOS-latest

Possible null reference assignment.

Check warning on line 161 in src/WeihanLi.Common/Helpers/InMemoryStream.cs

View workflow job for this annotation

GitHub Actions / Running tests on macOS-latest

Possible null reference assignment.

Check warning on line 161 in src/WeihanLi.Common/Helpers/InMemoryStream.cs

View workflow job for this annotation

GitHub Actions / Running tests on windows-latest

Possible null reference assignment.
MaxTimestamp = default,
Count = _messages.Count
};

if (_messages.Count > 0)
{
var minMessage = _messages.MinBy(item => item.Id, _comparer);
var maxMessage = _messages.MaxBy(item => item.Id, _comparer);
ArgumentNullException.ThrowIfNull(minMessage);
ArgumentNullException.ThrowIfNull(maxMessage);

streamInfo.MinId = minMessage.Id;
streamInfo.MinTimestamp = minMessage.Timestamp;
streamInfo.MaxId = maxMessage.Id;
streamInfo.MaxTimestamp = maxMessage.Timestamp;
}

return streamInfo.WrapTask();
}

Expand Down

0 comments on commit 4bc2ca5

Please sign in to comment.