perf(misc): append processed post ID to file
This commit is contained in:
+10
-3
@@ -15,15 +15,22 @@ class ProcessedPostsManager:
|
|||||||
return set()
|
return set()
|
||||||
|
|
||||||
def _save(self):
|
def _save(self):
|
||||||
|
"""Full rewrite — use for batch operations only."""
|
||||||
with open(self.file_path, "w", encoding="utf-8") as processed:
|
with open(self.file_path, "w", encoding="utf-8") as processed:
|
||||||
processed.write("\n".join(self.processed_posts))
|
processed.write("".join(f"{pid}\n" for pid in self.processed_posts))
|
||||||
|
|
||||||
def is_processed(self, post_id: int) -> bool:
|
def is_processed(self, post_id: int) -> bool:
|
||||||
return str(post_id) in self.processed_posts
|
return str(post_id) in self.processed_posts
|
||||||
|
|
||||||
def mark_processed(self, post_id: int):
|
def mark_processed(self, post_id: int):
|
||||||
self.processed_posts.add(str(post_id))
|
"""Mark a single post processed and append to file (no full rewrite)."""
|
||||||
self._save()
|
str_id = str(post_id)
|
||||||
|
if str_id in self.processed_posts:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.processed_posts.add(str_id)
|
||||||
|
with open(self.file_path, "a", encoding="utf-8") as f:
|
||||||
|
f.write(str_id + "\n")
|
||||||
|
|
||||||
def add_existing_posts(self, post_ids: List[int]):
|
def add_existing_posts(self, post_ids: List[int]):
|
||||||
for post_id in post_ids:
|
for post_id in post_ids:
|
||||||
|
|||||||
Reference in New Issue
Block a user