Cleanup unread alerts after moderation activity
Partial for #7423
If there are any unread alerts out there related to moderation activity that has been closed out, flag them as read.
My comment here also applies to this PR, I'm afraid. 🙁
It cannot attempt the deletion before the alert exists, because this logic actually queries the alert...
See https://github.com/SimpleMachines/SMF/pull/7516#issuecomment-1218200073 🙂
Yes, it is conceivable that the cleanup is attempted before the alert is posted (mainly if you're having system issues & cron isn't functioning). But that is such a narrow possibility, and the downside of that happening is so negligible, that I think we should stay with what we have here.
I modeled these PRs after pre-existing logic used elsewhere in SMF for cleaning up alerts, e.g., the cleanup after quote/mention removal logic.
You wrote that logic, emulated here.
For moderation activity and approvals, there will be sufficient time between those actions this gap should be virtually non-existent (again, unless there are system issues). For likes, especially if someone sits there twiddling the like link incessantly, there may be a discrepancy. But, it should be noted, that there was, in fact, a like performed. It's not inaccurate.
For 0.01% of the time, a once valid alert may remain after the fact. But the truth remains it was once valid.
This is not an accounting application with millions of transactions & critical sequencing. If so, I agree a rewrite of all of these functions would be necessary.
Now is not the time for a redesign. It is unnecessary.
These PRs had extensive testing before they were submitted, and have been executing in an active production environment for months after that with no issues.
I thought I had tested everything; just retested again...
The first two items in @Sesquipedalian 's list are more difficult to pin down... I actually don't think that logic is called from anywhere... I suspect when the 'modblock' changes were implemented, the older variants were cloned and modified, but never removed.
I may be missing something??? Anybody know how to invoke the logic on line 708/787???
Still testing the topic deletion... (I had thought #7515 would deal with deleted topics, and it will, for everyone except admins & global moderators...)
OK, I addressed the first two items by removing the unused logic.
I confirmed that the 3rd item is already addressed by #7515 . The benefit in that approach is it will not only address deleted/recycled topics, but also deleted/recycled messages, and board permissions changes as well. All variants of "now you see it, now you don't"...
What confused me earlier is that there was a delay in displaying the updated counter. It will only fix the counter when a recount occurs. Most alert-related activities will trigger a recount, e.g., marking alerts read, or viewing alerts. (Note also that the alert counter gets cached with other member info, and is impacted by the cache timeout as well...)
(At one point I had a "sledgehammer" approach PR, which would always reset the counter in Load.php. I opted against that as the counter does correct itself...)
I believe this one is ready now.