ssteenkiste / nettiers

Automatically exported from code.google.com/p/nettiers
1 stars 0 forks source link

Saving large sets of data is slow. #423

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Get an Tlist<> of entities around 2k.
2. call Datarepository.Save(entities);
3.

What is the expected output? What do you see instead?
I looked at the base code and noticed that save is calling:

        public virtual TList<Entity> Save(TransactionManager mgr, TList<Entity> entities)
        {
            foreach ( Entity entity in entities.DeletedItems )
            {
                Delete(mgr, entity);
            }

                foreach ( Entity entity in entities )
            {
                if (!entity.IsNew) Save(mgr, entity);
            }

                foreach ( Entity entity in entities )
            {
                if (entity.IsNew) Save(mgr, entity);
            }

            // Clear the items to delete list.
            entities.DeletedItems.Clear();
            return entities;
        }

There are 2 for loops at the end that do exactly the same thing and when they 
call the save function it already looks at the state of the entity.  There is 
no reason in doing the !entity.IsNew and entity.IsNew check in the first and 
second. i think these can be combined into one loop and it will work for both.  
Iterating over these 2 times is slow and unnecessary. Since the save method 
already does the check for each entity on its own.  Also in the first of the 
two loops if the entity is !entity.Isnew it means its should just have a state 
of changed.  Which will just be caught in the saves switch.

What version of .netTiers and CodeSmith are you using?
standard 5.3

Please provide any additional information below.

Original issue reported on code.google.com by Tomlinso...@gmail.com on 21 Jun 2012 at 11:37

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thinking about this why not just do one for loop and do the check in the save 
function on the entities state and if the entity is new or not. This saves 
looping the set multiple times. Loops get expensive when there are more than 
one and the sets are large.

Original comment by Tomlinso...@gmail.com on 21 Jun 2012 at 11:47