Skip to content

Commit 0a109da

Browse files
committed
Make crosspost message attachment cache limit to 100 entries in 'anti_crosspost' extension
1 parent e2b9427 commit 0a109da

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

pcbot/exts/anti_crosspost.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
logger = logging.getLogger(__name__)
1919

20-
fetched_attachments: dict[int, bytes] = {}
20+
fetched_attachments: OrderedDict[int, bytes] = OrderedDict()
2121

2222

2323
def hamming_distance_padded(str1, str2):
@@ -44,6 +44,10 @@ async def fetch_attachment(attachment: discord.Attachment, cache: bool = True) -
4444
if cache:
4545
fetched_attachments[attachment.id] = data
4646
logger.debug(f"Fetched attachment from source: {attachment.id}")
47+
48+
if len(fetched_attachments) > 100:
49+
fetched_attachments.popitem(last=False)
50+
4751
return data
4852

4953

0 commit comments

Comments
 (0)