GraphDiff icon indicating copy to clipboard operation
GraphDiff copied to clipboard

Updating a list of entities

Open DixonDs opened this issue 10 years ago • 3 comments

Currently, if we want to use GraphDiff to update a list of entities, we can only do this in a loop. Is it efficient, given that each graph is loaded by a separate request to the database? Can we make it better if we load a list of entities by a single query?

DixonDs avatar Feb 04 '15 22:02 DixonDs

Hi,

I haven't thought this through at all, but yes, probably. Have a look at the line of GraphDiffer that's loading the persisted graph via QueryLoader. I'd imagine one could quite easily create an overload to load a collection of graphs using a single query..

ghost avatar Jul 22 '15 11:07 ghost

I tried out this idea and it works great in my projects. A large batch process that updates thousands of complex graphs went from 34 to 2 minutes with a batch size of 100. I think I can downgrade to smaller Azure instances :-)

This were my changes (see fork):

  • changing IGraphDiffer and IQueryLoader from T to IEnumerable<T>
  • added additional extension method to DbContextExtensions (existing interfaces not changed)
  • creation of key predicate expression has to be extended to load all persisted entities at once
  • order of persisted/loaded entities can be different from updating entities and must be restored
  • prevent loading of new entities (see pull request)

All existing tests run fine with my changes to GraphDiffer and QueryLoader. Composite keys are still supported ((KeyA='a1' AND KeyB='b1') OR (KeyA='a2' AND KeyB='b2' OR ...) and simple int keys are optimized to ...Key in (1,2,3,4,5...).

mk1024 avatar Jul 30 '15 16:07 mk1024

@mk1024 I think it would be nice if you make a pull request with your changes;)

DixonDs avatar Jul 30 '15 16:07 DixonDs