Класс UnreadFreshnessQuery
For the accessible candidates of a collab (the collab main chat + its direct children), returns the freshest unread MESSAGE_ID (MAX(MESSAGE_ID) as a monotone-in-time surrogate) in each candidate's subtree, grouped by the candidate ("root" of its bucket). On MySQL every path (the single-user read path and the member fan-out) goes through the flat per-leaf statement ({@see fetchForMembers}): it is driven by the constant USER_ID equality on unread - an estimate the optimizer resolves by index dive, immune to per-key statistics - and every other access is an equality probe along the ancestor chain. Its cost is O(user's unread) regardless of the collab's size, and no plan can multiply two independent cardinalities. Any form that iterates candidates in SQL is forbidden here. A candidate-anchored variant with correlated freshness subqueries used to live in this class and melted production shards: for a DEPENDENT SUBQUERY the correlated value is unknown at plan time, no index dive is possible, and the skewed chat.PARENT_ID per-key averages made the optimizer re-drive each subquery from the user's unread rows - O(candidates x user's unread), minutes on collabs with thousands of task-chat candidates. Other dialects keep one aggregating ORM query per depth with id lists: on PostgreSQL id lists are planned via =ANY() without a dive limit and measured strictly faster, so that path must not be "unified" into the MySQL one.
Полное имя класса
Bitrix\Im\V2\Recent\PreviewSource\UnreadFreshnessQuery
Методы
Методы и их характеристики
-
__construct()public