优化保存已处理交易哈希的逻辑,合并新哈希并保持原有顺序
This commit is contained in:
7
main.py
7
main.py
@@ -182,8 +182,9 @@ def save_processed_hashes():
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
existing_data = []
|
||||
|
||||
# 合并新哈希
|
||||
updated_data = list(set(existing_data) | SEEN_TXHASHES)
|
||||
# 合并新哈希并去重,保持原有顺序
|
||||
new_hashes = [h for h in SEEN_TXHASHES if h not in existing_data]
|
||||
updated_data = existing_data + new_hashes
|
||||
|
||||
# 写回文件
|
||||
with open(HASH_FILE, "w", encoding="utf-8") as file:
|
||||
@@ -192,7 +193,7 @@ def save_processed_hashes():
|
||||
LOGGER.info(
|
||||
"成功更新%s,新增%d条哈希,总计%d条记录",
|
||||
HASH_FILE,
|
||||
len(SEEN_TXHASHES - set(existing_data)),
|
||||
len(new_hashes),
|
||||
len(updated_data),
|
||||
)
|
||||
except IOError as e:
|
||||
|
Reference in New Issue
Block a user