How to force the save to execute inmediately in active record?

Hi,

I am using active query. I am creating a model, and then after populating it, I am saving it. But I think that the save() is stacking up all the models pending to be saved, and they will be saved later. How can I force it to save and then forget about it?

Any help is appreciated

Update.

The problem was not that save() was not being executed, but memory was stacking up for some other unknown reason. The Active Records were taking up too much memory. I ended up creating a query and executing it, avoiding the usage of active records. This boosted the memory usage. Though it is still not perfect, it is currently 6 times better than before.

I don’t think so. Why do you think so? Could you explain it with some code fragments?

Are you using db transactions?

Thanks for your reply! I was pending to update this post. It is actually being saved. I thought it was not because the memory usage was stacking up really fast even though I set the active record to null after using it. I’m not sure why it was stacking up so fast though. At the end I did not create any active record, but I created a command and executed it, so it used less memory. It is still not perfect, but got a x6 boost.

AFAIK, the only source of memory leaks is behaviors, particularly AttributeTypecast.

Yes, it’s true that ActiveRecord is heavy and slow. It may be a show stopper in a certain scenario in which speed and lightness is the key players.

But I usually keep using ActiveRecord as long as no substantial drawback comes up, because it’s extremely convenient and easy to handle. It speeds up the development as a whole.

I don’t want to throw away ActiveRecord in exchange for a marginal improvement of speed and memory footprint. @maxkoa, I don’t want to offend you, but I’m a little afraid that you might fail to see the forest for the trees.

1 Like

No offense taken! @softark, but I really need the speed boost here. We need to somehow mark a list of messages as read. There are many conditions to be met, and there are users with more than 2000 messages that have not been marked. Using Active Records is taking more than a minute, which a normal user would not wait and would think that the program crashed. So the boost makes it more bareable. It is still not fast enough, but this should only happen once or twice, because I don’t expect the user to stack so many messages. There are users with more than 60.000 messages as unread (users with privileges and access to the ‘sub-users’ messages).

1 Like

Thank you @maxkoa for the reply.

I agree that it makes sense to pursuit speed here. I would want to throw away the ActiveRecord in this sceanrio, too.