|
|
|
Forum Member
      
Group: Forum Members
Last Login: Today @ 11:59:26
Posts: 34,
Visits: 919
|
|
Hello!
I have a class which references many other classes as 1:n and n:m. When I execute anObject.AsIObject().Delete(), it may take up to a second (!) to delete a single instance. But, if I go over all its associations and do something like this:
if (anObject.AssociationX.Count==0) anObject.AssociationX.Clear();
it gets deleted blazing fast.
Does anyone have an idea why clearing empty associations makes deletion to execute with a normal speed, while without it it is very slow? The database presently has about 800'000 records in all tables.
Take care,
Dmitry
|
|
|
|
|
Supreme Being
      
Group: Administrators
Last Login: 2010-07-21 00:21:24
Posts: 1 228,
Visits: 1 373
|
|
No, I can't tell why this improves the speed. but it sounds like there is either a bug, or room for optimizations here... Could you check with the EcoSpaceDebugger if there is any difference in which SQL statements are executed when you clear before or not?
/Jonas Hogstrom [CapableObjects]
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: Today @ 11:08:06
Posts: 256,
Visits: 2 317
|
|
Clearing the associations will merely unlink the objects. If the association is 1..* then it will load in the child objects anyway, but if it is *..* it will only load in the link objects.
I think the difference however comes in that when you delete with links ECO has to check each of the child objects to see if those are permitted to be deleted too (if you have cascade delete, or they are composite). Which in turn could mean that each of those objects then load up their composite objects to see if they are permitted to be deleted, and so on.
Is your association composite. Do the child objects also have composite associations of their own?
Pete
====
Pete
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 2010-05-15 22:36:10
Posts: 188,
Visits: 451
|
|
| > if (anObject.AssociationX.Count==0) anObject.AssociationX.Clear(); I'm sure it is nothing to do at all in this case
/Efim
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: Today @ 11:59:26
Posts: 34,
Visits: 919
|
|
Many of the associations are composite and link to other classes. Indeed, if there WERE objects in those associations it could take longer time to delete. But the associations are empty, and deletion takes long time anyway, while clearing EMPTY associations speeds it up a lot. I know very well that this is strange and looks like a shaman thing, though it does behave this way.
Best regards,
Dmitry
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: Today @ 11:08:06
Posts: 256,
Visits: 2 317
|
|
A----B----C
If you delete A then all B must be loaded so that ECO can also load all C relating to all B.
The fact that you are clearing the association is irrelevant, the important part of your code is SomeObject.SomeAssociation.Count, which loads in the objects in order to tell you how many are in the collection. I suspect all you are doing is loading the objects elsewhere and then noticing how much faster the delete is, or are you timing all of this code?
====
Pete
|
|
|
|