Trying to figure out best practice here.
I am writing some end points that will essentially combine a group of objects if their dates become contiguous.
Say there are three objects I want to group.
obj1 = {id: 1, start: 1/1/18, end: 1/2/18}
obj2 = {id: 2, start: 1/2/18, end: 1/3/18}
obj3 = {id: 3, start: 1/4/18, end: 1/5/18}
Are there any performance benefits or best practices to either of the following -
Create one new object which is essentially the 3 previous objects grouped together by date. Then delete the three other objects.
obj4 = {id: 4, start: 1/1/18, end: 1/5/18}
obj1.delete()
obj2.delete()
obj3.delete()
or
Update one objects fields to represent the new dates. Then delete the other two objects.
obj1.end = 1/5/18
obj1.save()
obj2.delete()
obj3.delete()
Just pseudo code here, but this is in a django app.
Thanks
This depends on the database, but PostgreSQL (since you mentioned it in the tags) generally implements UPDATEs as a DELETE followed by an INSERT anyway, so the difference should be neglegible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With