gavinzli commited on
Commit
5edd2db
·
1 Parent(s): 1d5b077

Refactor email indexing logic: improve check for already indexed emails and enhance logging

Browse files
Files changed (1) hide show
  1. app/controllers/mail.py +4 -5
app/controllers/mail.py CHANGED
@@ -78,11 +78,10 @@ def list_emails(service, messages):
78
  metadata = {}
79
  logger.info("vectorstore.index_to_docstore_id: %s", list(vectorstore.index_to_docstore_id.values()))
80
  logger.info("type: %s", type(vectorstore.index_to_docstore_id.values()))
81
- if msg["id"] in list(vectorstore.index_to_docstore_id.values()):
82
- logger.info("Email already exists in the database.")
83
- existing_ids = list(vectorstore.index_to_docstore_id.values())
84
- logger.info("Existing email IDs in the database: %s", existing_ids)
85
- continue
86
  for header in msg["payload"]["headers"]:
87
  if header["name"] == "From":
88
  metadata["from"] = header["value"]
 
78
  metadata = {}
79
  logger.info("vectorstore.index_to_docstore_id: %s", list(vectorstore.index_to_docstore_id.values()))
80
  logger.info("type: %s", type(vectorstore.index_to_docstore_id.values()))
81
+ for docstore_id in list(vectorstore.index_to_docstore_id.values()):
82
+ if docstore_id.startswith(message["id"]):
83
+ logger.info("Already indexed: %s", message["id"])
84
+ continue
 
85
  for header in msg["payload"]["headers"]:
86
  if header["name"] == "From":
87
  metadata["from"] = header["value"]