新增了完整的Confluence集成插件,包含以下核心功能: 1. 基础认证与配置管理,支持API Token和OAuth2两种认证方式 2. 评论去重、权限控制与提及解析 3. 知识库检索与页面内容处理 4. 评论收发、编辑删除与流式回复支持 5. 附件与页面标签管理 6. 内容属性存储与AI元数据管理 7. Webhook事件接收与处理 8. 完整的插件配置与状态检查
35 lines
998 B
Python
35 lines
998 B
Python
import time
|
|
|
|
|
|
class CommentDeduplicator:
|
|
def __init__(self, max_size: int = 50_000, ttl_seconds: int = 600):
|
|
self._max_size = max_size
|
|
self._ttl = ttl_seconds
|
|
self._cache: dict[str, float] = {}
|
|
|
|
def is_duplicate(self, comment_id: str) -> bool:
|
|
self._evict_expired()
|
|
return comment_id in self._cache
|
|
|
|
def mark(self, comment_id: str):
|
|
self._evict_expired()
|
|
self._cache[comment_id] = time.time()
|
|
self._evict_oldest_if_needed()
|
|
|
|
def _evict_expired(self):
|
|
now = time.time()
|
|
expired = [cid for cid, ts in self._cache.items() if now - ts > self._ttl]
|
|
for cid in expired:
|
|
del self._cache[cid]
|
|
|
|
def _evict_oldest_if_needed(self):
|
|
while len(self._cache) > self._max_size:
|
|
oldest = min(self._cache, key=self._cache.get)
|
|
del self._cache[oldest]
|
|
|
|
def clear(self):
|
|
self._cache.clear()
|
|
|
|
def __len__(self) -> int:
|
|
return len(self._cache)
|