[FIX] mail: missing notif in systray
When handling notifications in Odoo and tagging the user on a SO/ task / whatever, the messaging counter is increased by 1 and the notification appears in the inbox, but not in the systray.
This is because the needaction is wrongly set with self, which is the user that is doing the action, not the user that should be notified.
This commit fixes the issue by correctly setting user when it comes to the personalized notify
I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr
updated query numbers @seb-odoo
Hi there 👋
Seems to make sense logically but we could probably keep the batched call and edit the formatted message with the user-specific stuff afterwards (extracting "for_current_user" from "message_format"). As it stands it seems like we'll do a search for every notified partner in
_message_format_personalized_prepare(also task ids are super cool)
Heeey 👋 ,
I was thinking about the same way to handle that but it didn't work well. The reason was if we extracted the for_current_user part out of the method, we needed to re-browser and read fields from message_sudo and record when calling it again, which creates more queries than not extracting it.
And actually, when sending to a lot of recipients at the same time, there is only one query extra for reading the user_ids, which is not possible to avoid with. See test with more than one partner https://github.com/odoo/odoo/pull/168855/files#diff-6966285e759da835e3575ea5487cc9d843abaac6fd254491cf05c10b2aed4cfaR1390
the extra query is 2024-06-18 11:15:53,202 1241098 WARNING odoo odoo.sql_db: [0.131 ms] query: SELECT "res_users"."id", "res_users"."partner_id", "res_users"."active" FROM "res_users" LEFT JOIN "res_partner" AS "res_users__partner_id" ON ("res_users"."partner_id" = "res_users__partner_id"."id") WHERE ("res_users"."partner_id" IN (303)) ORDER BY "res_users__partner_id"."name" , "res_users"."login"
And this is a bug reported directly in the channel so there is no task for that... :(
test_message_post
From what I see it only adds one query because it has to do the "prepare" stuff once anyway, if you increase the number of recipients that use inbox by 1, you increase the number of queries by 3. So for a realistic case of 5 followers all using "inbox" that's still ~15 queries. Compared to before this fix where the number of queries is constant regardless of follower count.
we needed to re-browser and read fields from message_sudo and record when calling it again
Hm, do we clear the cache or something? Shouldn't it be the same whether we call it inside _message_format or outside? As there doesn't seem to be a search in the for_current_user values
If it really can't be done that's that but it seems a tad expensive
Ok, I understand what you mean. let's try I pushed the new code and hopefully, it works better.
Thank you for the investigation here!
I'll fix it in this PR: https://github.com/odoo/odoo/pull/171944
