Skip to content

Cosmos DB for Events#61

Open
lizard-boy wants to merge 4 commits into
mainfrom
cosmosevents
Open

Cosmos DB for Events#61
lizard-boy wants to merge 4 commits into
mainfrom
cosmosevents

Conversation

@lizard-boy

@lizard-boy lizard-boy commented Oct 19, 2024

Copy link
Copy Markdown

Type of change

- [ ] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Code changes

  • file.ext: Description of what was changed and why

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • If making database changes - make sure you also update Entity Framework queries and/or migrations
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

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.

  • Added src/Core/Models/Data/EventItem.cs with a new EventItem class for Cosmos DB event data handling
  • Introduced src/Core/Repositories/Cosmos/EventRepository.cs for managing events in Cosmos DB
  • Modified src/EventsProcessor/AzureQueueHostedService.cs to support Cosmos DB alongside existing TableStorage
  • Updated src/SharedWeb/Utilities/ServiceCollectionExtensions.cs to register Cosmos DB EventRepository

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

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() {}

Copy link
Copy Markdown

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; }

Copy link
Copy Markdown

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; }

Copy link
Copy Markdown

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")

Copy link
Copy Markdown

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

Comment on lines +36 to +37
_database = _client.GetDatabase("events");
_container = _database.GetContainer("events");

Copy link
Copy Markdown

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

Comment on lines +102 to +103
// TODO: How should we handle the partition yet? Perhaps something like table storage did with
// orgId, userId, providerId

Copy link
Copy Markdown

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

Comment on lines +111 to +120
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);
}

Copy link
Copy Markdown

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

Comment on lines +139 to +149
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;
}
}

Copy link
Copy Markdown

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

private async Task ExecuteAsync(CancellationToken cancellationToken)
{
var storageConnectionString = _configuration["azureStorageConnectionString"];
var cosmosConnectionString = _configuration["cosmosConnectionString"];

Copy link
Copy Markdown

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

Comment on lines +64 to +66
IEventRepository repo = string.IsNullOrWhiteSpace(cosmosConnectionString) ?
new Core.Repositories.TableStorage.EventRepository(storageConnectionString) :
new Core.Repositories.Cosmos.EventRepository(cosmosConnectionString);

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants