bilal-fazlani / tracker-enabled-dbcontext

Tracker-enabled DbContext offers you to implement full auditing in your database
https://tracker-enabled-dbcontext.bilal-fazlani.com/
Other
217 stars 110 forks source link

Performance Issue #124

Open brianv509 opened 8 years ago

brianv509 commented 8 years ago

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();
aboyaniv commented 7 years ago
  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