mirror of
https://github.com/markqvist/NomadNet.git
synced 2026-10-26 02:48:48 -04:00
RRC: filter and *then* apply the history cap
This commit is contained in:
parent
ad10301569
commit
bec78cf1e5
1 changed files with 10 additions and 15 deletions
|
|
@ -720,6 +720,7 @@ class RRCHub:
|
||||||
def _load_history(self):
|
def _load_history(self):
|
||||||
with self._lock:
|
with self._lock:
|
||||||
rooms = list(self.messages.keys())
|
rooms = list(self.messages.keys())
|
||||||
|
filter_msgs = self._filter_history()
|
||||||
for room in rooms:
|
for room in rooms:
|
||||||
if not self._persistable_room(room):
|
if not self._persistable_room(room):
|
||||||
continue
|
continue
|
||||||
|
|
@ -732,38 +733,32 @@ class RRCHub:
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
window.append(cbor.load(f))
|
entry = cbor.load(f)
|
||||||
except EOFError:
|
except EOFError:
|
||||||
break
|
break
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
decode_error = ex
|
decode_error = ex
|
||||||
break
|
break
|
||||||
|
m = self._msg_from_entry(room, entry)
|
||||||
|
if m is None:
|
||||||
|
continue
|
||||||
|
if filter_msgs and (m.kind == "system" or m.kind == "notice"):
|
||||||
|
continue
|
||||||
|
window.append(m)
|
||||||
except OSError as ex:
|
except OSError as ex:
|
||||||
self._log("history load failed for #"+room+": "+str(ex), RNS.LOG_ERROR)
|
self._log("history load failed for #"+room+": "+str(ex), RNS.LOG_ERROR)
|
||||||
continue
|
continue
|
||||||
if decode_error is not None:
|
if decode_error is not None:
|
||||||
self._log("history file for #"+room+" is corrupt, truncating to last "+str(len(window))+" valid messages: "+str(decode_error), RNS.LOG_ERROR)
|
self._log("history file for #"+room+" is corrupt, truncating to last "+str(len(window))+" valid messages: "+str(decode_error), RNS.LOG_ERROR)
|
||||||
msgs = []
|
|
||||||
filter_msgs = self._filter_history()
|
|
||||||
for e in window:
|
|
||||||
m = self._msg_from_entry(room, e)
|
|
||||||
if m is not None:
|
|
||||||
if filter_msgs:
|
|
||||||
should_filter = False
|
|
||||||
if m.kind == "system": should_filter = True
|
|
||||||
elif m.kind == "notice": should_filter = True
|
|
||||||
if should_filter: continue
|
|
||||||
|
|
||||||
msgs.append(m)
|
|
||||||
with self._lock:
|
with self._lock:
|
||||||
self.messages[room] = msgs
|
self.messages[room] = list(window)
|
||||||
|
|
||||||
def _clean_history(self):
|
def _clean_history(self):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
cleaned = False
|
cleaned = False
|
||||||
remove_after = self._ephemeral_notices_history()
|
remove_after = self._ephemeral_notices_history()
|
||||||
if now > self._last_history_clean + self.CLEAN_HISTORY_INTERVAL:
|
if now > self._last_history_clean + self.CLEAN_HISTORY_INTERVAL:
|
||||||
RNS.log(f"Cleaning loaded message history", RNS.LOG_DEBUG)
|
RNS.log(f"Cleaning loaded message history", RNS.LOG_DEBUG)
|
||||||
with self._lock:
|
with self._lock:
|
||||||
try:
|
try:
|
||||||
for r in self.messages:
|
for r in self.messages:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue