Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion base_tier_validation/models/tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,18 @@ def restart_validation(self):
def _update_counter(self, review_counter):
self.review_ids._update_review_status()
channel = "base.tier.validation/updated"
self.env.user.partner_id._bus_send(channel, review_counter)
# Notify the reviewers whose pending count actually changes, not the
# acting user. Sending the delta to ``self.env.user`` made unrelated
# users' systray counters drift (even negative) whenever someone acted
# on a tier-validated record without being one of its reviewers. When
# the reviews are already gone (deletions), fall back to the acting
# user. The client recomputes the absolute count on receipt, so the
# exact audience only affects how promptly a reviewer sees the update.
partners = self.review_ids.mapped("reviewer_ids.partner_id")
if not partners:
partners = self.env.user.partner_id
for partner in partners:
partner._bus_send(channel, review_counter)

def unlink(self):
self.mapped("review_ids").unlink()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Component, useState} from "@odoo/owl";
import {Dropdown} from "@web/core/dropdown/dropdown";
import {registry} from "@web/core/registry";
import {useDebounced} from "@web/core/utils/timing";
import {useDiscussSystray} from "@mail/utils/common/hooks";
import {useDropdownState} from "@web/core/dropdown/dropdown_hooks";
import {useService} from "@web/core/utils/hooks";
Expand All @@ -16,18 +17,57 @@ export class TierReviewMenu extends Component {
this.orm = useService("orm");
this.store = useState(useService("mail.store"));
this.action = useService("action");
this.busService = useService("bus_service");
this.dropdown = useDropdownState();
this.fetchPending = false;
this.fetchRunning = false;
// Keep the badge live and correct: re-fetch the authoritative count
// whenever a tier review changes server-side, instead of nudging a
// running +/- delta. The absolute value is a len() and so can never go
// negative, which a delta could when an update reaches a user for whom
// the review was never part of their pending count.
//
// That re-fetch is not free: ``review_user_count`` costs a handful of
// queries per pending review, and the notification is broadcast to
// every reviewer. Approving a batch of documents therefore fans out to
// (reviewers x open tabs x documents) recounts, which is enough to
// occupy every HTTP worker. Coalesce the bursts: the leading edge keeps
// an isolated change instant, the trailing edge settles the final value.
this.debouncedFetch = useDebounced(() => this.fetchSystrayReviewer(), 15000, {
immediate: true,
trailing: true,
});
this.fetchSystrayReviewer();
this.busService.subscribe("base.tier.validation/updated", () =>
this.debouncedFetch()
);
this.busService.start();
}

async fetchSystrayReviewer() {
const groups = await this.orm.call("res.users", "review_user_count");
let total = 0;
for (const group of groups) {
total += group.pending_count || 0;
// A recount can outlast the debounce window on a busy database. Never
// let them overlap: remember that something changed and re-run once,
// instead of stacking concurrent calls on top of a slow one.
if (this.fetchRunning) {
this.fetchPending = true;
return;
}
this.fetchRunning = true;
try {
const groups = await this.orm.call("res.users", "review_user_count");
let total = 0;
for (const group of groups) {
total += group.pending_count || 0;
}
this.store.tierReviewCounter = total;
this.store.tierReviewGroups = groups;
} finally {
this.fetchRunning = false;
}
if (this.fetchPending) {
this.fetchPending = false;
await this.fetchSystrayReviewer();
}
this.store.tierReviewCounter = total;
this.store.tierReviewGroups = groups;
}

availableViews() {
Expand Down

This file was deleted.

Loading