Skip to content

Conversation

@Jklawreszuk
Copy link
Collaborator

@Jklawreszuk Jklawreszuk commented Jun 13, 2023

PR Details

Description

PR migrates current ASP.NET project to ASP.NET Core + EntityFramework/Dapper. I've also rearranged code refactored code to make it more readable. Additionally, project has Swagger support to easily call endpoints.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)

Todo

  • - Finish following endpoints :
    • ActivityMetrics.Controller. GetCrashesPerVersion - takes about 2 minutes to load. I was not able to materialize the query. Probably need to create a MetricCache table, create a job using i.e HangFire lib or SQL agent
    • ActivityMetrics.Controller.GetHighUsage - I need to test this, sometimes it takes too long to load.
  • - Create SQL script to apply EF Core in production
  • - Complete JS client
  • - Implement database seeder
  • - Test app when it is finished

I am leaving this PR as a WIP because I need a break. Though if you want to help, please feel free to collaborate and contribute your ideas or suggestions through my fork or anywhere😊

@VaclavElias
Copy link
Contributor

@Jklawreszuk

Could you send met a link / zip to the database dump you used and I can test it?

Copy link
Member

@manio143 manio143 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! Left some suggestions.

public IEnumerable<ProjectsUsersAggregation> GetProjectsUsers()
{
var result = _metricDbContext.MetricEvents
.Where(a => a.MetricId == 19)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put that 19 in a names constant and explain which metric it represents (like const int XxxMetricId = 19;)?

g.Sum(x => x.Count > 3 ? 1 : 0),
g.Sum(x => x.Count > 5 ? 1 : 0)
))
.ToList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ToListAsync() like below - applies in other methods as well

/// </summary>
/// <returns>The installs count in the last 30 days per day</returns>
[HttpGet]
[Route("installs-last-days")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: route path can be moved up into the [HttpGet]

return Ok();
}

var clock = Stopwatch.StartNew();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to stop the Stopwatch before exiting this method?

Timestamp = overrideTime ?? default
};

var metricAsJson = JsonConvert.SerializeObject(newMetric);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to move this serialization into the if block - this way we don't do it unnecessarily on the happy path.

builder.Services.AddDbContext<MetricDbContext>(opt =>
{
opt.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"),
options => options.CommandTimeout(999999999));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would strongly suggest making this smaller 😄
15 minutes timeout should probably be enough - it's not like people will be waiting that long before getting discouraged anyways and maybe the query needs to be further optimized or db upgraded if it takes that long...

Copy link
Collaborator Author

@Jklawreszuk Jklawreszuk Jun 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, yes, that was intended, just for testing purposes as some queries are very time consuming. I think I will remove it completely and try to cache some queries using materialized views or additonal table

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the caching, from .NET 7 you can cache very easily through minimal API, or a controller through OutputCache, maybe you know about that.

https://learn.microsoft.com/en-us/aspnet/core/performance/caching/output?view=aspnetcore-7.0

image

## Prerequisites

- `ASPNET_ENVIRONMENT`: Set this variable to `Development` if you want to run the application in a testing environment. In the development environment, the application will connect to a non-Local SQL Server, allowing you to run the application on any operating system (i.e. [by using docker image](https://hub.docker.com/_/microsoft-mssql-server).).
- `--seed-metrics` (recommended): Set this argument if you want to seed the database with initial data.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this in Program.cs

@tebjan tebjan marked this pull request as draft August 7, 2023 19:48
@Jklawreszuk
Copy link
Collaborator Author

I am no longer working this PR, see #2261

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