新增小红书、XMPP、元宝、Zalo 四个渠道扩展。 小红书渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, media, status, window XMPP 渠道扩展主要模块:plugin, config, gateway, outbound, streaming, pairing, security, dedupe, accounts, commands, muc, rate_limiter, stanza_utils, status, monitor 元宝渠道扩展主要模块:plugin, client, config_schema, gateway, outbound(chunk/queue/transport), inbound(dispatcher), streaming, pairing, security, accounts, actions, commands, codec(biz/conn), session, shared, utils Zalo 渠道扩展主要模块:api, config, gateway, webhook, outbound, pairing, security, session, polling, monitor, status
33 lines
936 B
Python
33 lines
936 B
Python
import time
|
|
from collections import OrderedDict
|
|
|
|
|
|
class DedupeTracker:
|
|
def __init__(self, max_size: int = 2000, ttl_seconds: int = 300):
|
|
self._cache: OrderedDict[str, float] = OrderedDict()
|
|
self._max_size = max_size
|
|
self._ttl = ttl_seconds
|
|
|
|
def has(self, key: str) -> bool:
|
|
if not key:
|
|
return False
|
|
if key in self._cache:
|
|
return True
|
|
self._expire()
|
|
return key in self._cache
|
|
|
|
def add(self, key: str) -> None:
|
|
if not key:
|
|
return
|
|
self._expire()
|
|
self._cache[key] = time.monotonic()
|
|
self._cache.move_to_end(key)
|
|
while len(self._cache) > self._max_size:
|
|
self._cache.popitem(last=False)
|
|
|
|
def _expire(self) -> None:
|
|
now = time.monotonic()
|
|
expired = [k for k, ts in self._cache.items() if now - ts > self._ttl]
|
|
for k in expired:
|
|
del self._cache[k]
|