增强社交统计并扩展 value_rank 社交榜单命令
- 在消息入库增量链路中回填 unique_interactors,实现去重互动人数实时更新 - 新增社交热度榜命令:社交热度榜 [名次],按互动分/被@/主动@展示 - 新增搭子榜命令:搭子榜 [名次],按无向关系边聚合展示成员组合 - 扩展 ValueRankDB 查询接口,支持社交热度与搭子关系窗口聚合 - 同步更新 value_rank 配置命令列表与帮助文案
This commit is contained in:
@@ -258,10 +258,63 @@ class MessageStorageDB(BaseDBOperator):
|
||||
""",
|
||||
receiver_social_rows,
|
||||
)
|
||||
|
||||
# 4) 回填 unique_interactors:针对本条消息受影响的用户实时重算“去重互动人数”。
|
||||
affected_user_ids = [sender_id, *clean_mentioned_ids]
|
||||
self._refresh_unique_interactors(stat_date, group_id, affected_user_ids)
|
||||
except Exception as e:
|
||||
# 社交图统计属于增强链路,不能反向影响主消息入库稳定性。
|
||||
self.LOG.error(f"写入社交图增量数据失败: {e}")
|
||||
|
||||
def _refresh_unique_interactors(self, stat_date: str, group_id: str, user_ids: List[str]) -> None:
|
||||
"""重算并回填用户在指定日期内的去重互动人数。
|
||||
|
||||
定义:
|
||||
- 某用户当天主动@过的人 + 被谁@过(去重并集)
|
||||
"""
|
||||
if not user_ids:
|
||||
return
|
||||
|
||||
deduped_user_ids = []
|
||||
seen = set()
|
||||
for uid in user_ids:
|
||||
normalized_uid = str(uid or "").strip()
|
||||
if not normalized_uid or normalized_uid in seen:
|
||||
continue
|
||||
seen.add(normalized_uid)
|
||||
deduped_user_ids.append(normalized_uid)
|
||||
|
||||
for uid in deduped_user_ids:
|
||||
try:
|
||||
row = self.execute_query(
|
||||
"""
|
||||
SELECT COUNT(DISTINCT partner_id) AS partner_count
|
||||
FROM (
|
||||
SELECT mentioned_user_id AS partner_id
|
||||
FROM t_message_mentions
|
||||
WHERE stat_date = %s AND group_id = %s AND sender_id = %s
|
||||
UNION
|
||||
SELECT sender_id AS partner_id
|
||||
FROM t_message_mentions
|
||||
WHERE stat_date = %s AND group_id = %s AND mentioned_user_id = %s
|
||||
) t
|
||||
""",
|
||||
(stat_date, group_id, uid, stat_date, group_id, uid),
|
||||
fetch_one=True,
|
||||
) or {}
|
||||
partner_count = int(row.get("partner_count") or 0)
|
||||
|
||||
self.execute_update(
|
||||
"""
|
||||
UPDATE t_value_rank_social_daily
|
||||
SET unique_interactors = %s, update_time = CURRENT_TIMESTAMP
|
||||
WHERE stat_date = %s AND group_id = %s AND user_id = %s
|
||||
""",
|
||||
(partner_count, stat_date, group_id, uid),
|
||||
)
|
||||
except Exception as e:
|
||||
self.LOG.error(f"回填 unique_interactors 失败: group={group_id}, user={uid}, err={e}")
|
||||
|
||||
def get_recent_messages(self, group_id: str, hours_ago: int = 8, min_content_length: int = 6) -> List[Dict]:
|
||||
"""获取最近的消息"""
|
||||
sql = """
|
||||
|
||||
Reference in New Issue
Block a user