-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cosmos DB for Events #61
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 file(s) reviewed, 11 comment(s)
Edit PR Review Bot Settings | Greptile
|
||
public class EventItem : IEvent | ||
{ | ||
public EventItem() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider removing the empty constructor if it's not explicitly needed
} | ||
|
||
[JsonPropertyName("id")] | ||
public string Id { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider making Id property init-only to prevent modification after creation
[JsonPropertyName("saId")] | ||
public Guid? ServiceAccountId { get; set; } | ||
[JsonPropertyName("domain")] | ||
public string DomainName { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: DomainName should be nullable (string?) for consistency with other properties
private readonly Container _container; | ||
|
||
public EventRepository(GlobalSettings globalSettings) | ||
: this("TODO") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Replace 'TODO' with actual connection string retrieval from globalSettings
_database = _client.GetDatabase("events"); | ||
_container = _database.GetContainer("events"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider using configuration for database and container names instead of hardcoding
// TODO: How should we handle the partition yet? Perhaps something like table storage did with | ||
// orgId, userId, providerId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Implement a proper partitioning strategy before production use
public Task CreateManyAsync(IEnumerable<IEvent> events) | ||
{ | ||
// ref: https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/tutorial-dotnet-bulk-import | ||
var tasks = new List<Task>(); | ||
foreach (var e in events) | ||
{ | ||
tasks.Add(CreateAsync(e)); | ||
} | ||
return Task.WhenAll(tasks); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider using Cosmos DB bulk operations for better performance when creating multiple events
var result = new PagedResult<IEvent>(); | ||
while (iterator.HasMoreResults) | ||
{ | ||
var response = await iterator.ReadNextAsync(); | ||
result.Data.AddRange(response); | ||
if (response.Count > 0) | ||
{ | ||
result.ContinuationToken = response.ContinuationToken; | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: This pagination implementation may not handle large result sets efficiently. Consider implementing server-side pagination
@@ -54,12 +55,15 @@ public void Dispose() | |||
private async Task ExecuteAsync(CancellationToken cancellationToken) | |||
{ | |||
var storageConnectionString = _configuration["azureStorageConnectionString"]; | |||
var cosmosConnectionString = _configuration["cosmosConnectionString"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider using a more descriptive configuration key, such as 'cosmosDbConnectionString' for clarity
IEventRepository repo = string.IsNullOrWhiteSpace(cosmosConnectionString) ? | ||
new Core.Repositories.TableStorage.EventRepository(storageConnectionString) : | ||
new Core.Repositories.Cosmos.EventRepository(cosmosConnectionString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: This logic might be better placed in a factory method or dependency injection setup
Type of change
Objective
Code changes
Before you submit
dotnet format --verify-no-changes
) (required)Greptile Summary
This pull request introduces Cosmos DB support for event handling in the server application, focusing on the implementation of a new EventItem class and EventRepository for Cosmos DB integration.
src/Core/Models/Data/EventItem.cs
with a newEventItem
class for Cosmos DB event data handlingsrc/Core/Repositories/Cosmos/EventRepository.cs
for managing events in Cosmos DBsrc/EventsProcessor/AzureQueueHostedService.cs
to support Cosmos DB alongside existing TableStoragesrc/SharedWeb/Utilities/ServiceCollectionExtensions.cs
to register Cosmos DB EventRepository