You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When this code executes, it's extremely slow because of the select query after the insert. My understanding is that setting the reload option to false should suppress the query. If this is not the way, how would I do that?
Reacted by Ray Chavez, Hoon Oh, Mamouri, beeth0ven, Micael Levi L. Cavalcante, Gady, Volodymyr V., Jeremy Casey, AlexFromXD and William Cadenas
It sounds like this option only works for save, which is unfortunate because save was not cascading the relationships for me. I switched over to explicitly inserting and updating all the entities in my entity graph.
One detail I forgot to mention earlier is that the query after the insert was slow due to setting the orderBy option on the entity. I resolved the issue by removing the option and performing the order by where I needed it.
Any plans to implement fix resolve this? I'm hitting up against this again, and I don't want to have to write raw SQL every time I need fast inserts. I feel like the reload negates the performance benefits of using insert, especially since it's creating a select statement for each record.
Reacted by ZhelinCheng, Alexis Sécher, Piotr and Fırat Çetiner
I've already converted the code, and I don't want to change it now, but thank you for showing me this! I'll use it the next time I need to prevent reload.
For whoever ends up here, keep in mind that using updateEntity(false) causes your inserted identities not to be copied back into the object being inserted, and neither in the InsertResult.identifiers array. The workaround is to manually copy them from the raw result, which is a bit meh, especially for bulk inserts.
Relates to #5348, I added a proposal to address this here.
Reacted by Y Kaneko, Jakub Hrášek and Ignacio Baixas
Th provided workaround doesn't work. It should be possible to do reload: false on insert operation as well. Save operation updates the row if entity already exist. It definitely should be possible to do well performing insert without selecting first. We should be fine with simply catching a duplicate error and resolve it!
Reacted by Amir Khoshbakht, Adem and Guilherme Viana
Activity
liaozhongwu commentedon Sep 6, 2019
I fixed it by using save and { reload: false }, Any idea about insert?
nrcmkoh commentedon Sep 6, 2019
It sounds like this option only works for save, which is unfortunate because save was not cascading the relationships for me. I switched over to explicitly inserting and updating all the entities in my entity graph.
One detail I forgot to mention earlier is that the query after the insert was slow due to setting the orderBy option on the entity. I resolved the issue by removing the option and performing the order by where I needed it.
nrcmkoh commentedon Dec 17, 2019
Any plans to implement fix resolve this? I'm hitting up against this again, and I don't want to have to write raw SQL every time I need fast inserts. I feel like the reload negates the performance benefits of using
insert, especially since it's creating a select statement for each record.asecher commentedon Jan 19, 2020
@nrcmkoh You can use updateEntity(false) with an insert query builder like this:
nrcmkoh commentedon Jan 20, 2020
I've already converted the code, and I don't want to change it now, but thank you for showing me this! I'll use it the next time I need to prevent reload.
hypeofpipe commentedon Nov 4, 2020
You saved our costs! Great question and great answers!
dangphu2412 commentedon Feb 26, 2021
You can easily turn it off in .save() method like the code below:
await user.save(user, { reload: false });coyoteecd commentedon Mar 4, 2021
For whoever ends up here, keep in mind that using
updateEntity(false)causes your inserted identities not to be copied back into the object being inserted, and neither in the InsertResult.identifiers array. The workaround is to manually copy them from the raw result, which is a bit meh, especially for bulk inserts.Relates to #5348, I added a proposal to address this here.
imnotjames commentedon Jul 10, 2021
This was answered.
updateEntity(false)prevents the select.FrancoCorleone commentedon Aug 5, 2022
Th provided workaround doesn't work. It should be possible to do
reload: falseon insert operation as well. Save operation updates the row if entity already exist. It definitely should be possible to do well performing insert without selecting first. We should be fine with simply catching a duplicate error and resolve it!