bilal-fazlani/tracker-enabled-dbcontext

Performance Issue

brianv509 opened this issue · 1 comments

I have a scenario where I need to soft delete ~2500 rows at a time. Im looking to see if there is a better way to perform this task to get some quicker response times. Maybe some bulk insert with the audit logging?

Right now the breakdown is as follows:
-Initial select statement into the context is 2mins (very slow)
-Soft Delete update statement is 11secs (slow)
-The Audit log inserts is 41secs (very slow)
I’ve also try to just do a SQL query as a base line and it takes 1sec to perform all tasks.

Here is the code im executing:


//Pull list of everything that needs to be updated
var locationFixtures = Context.LocationFixtures.Where(lf => lf.FixtureId == fixtureId);

foreach (var entity in locationFixtures)
{
    Context.LocationFixtures.Attach(entity);
    entity.IsDeleted = true;
    entity.DeletedDateTime = DateTimeOffset.UtcNow;
}

Context.SaveChanges();

  1. you don't need to do Attach (entity) you are pooing the entities from the database. (remove the line)
  2. set GlobalTrackingConfig.DisconnectedContext = false; see https://github.com/bilal-fazlani/tracker-enabled-dbcontext/wiki/0.-Techniques