(20250118) Ready to test Mail Sync (Cron) on the server.
This commit is contained in:
@@ -474,31 +474,32 @@ class GmailController(MailController):
|
||||
# Start by assuming failure:
|
||||
sync_result = MailSyncOneResult()
|
||||
|
||||
# If we've not been forced to re-sync the mail message,
|
||||
# we first check if the mail already exists in our database:
|
||||
if not force_sync:
|
||||
mail_records = await self.get_message_previews(
|
||||
mongo_data_conn = mongo_data_conn,
|
||||
token_ids = [ObjectId(auth_token.authTokenId)],
|
||||
limit = 1,
|
||||
skip = 0,
|
||||
additional_filter = {
|
||||
"tokenId": ObjectId(auth_token.authTokenId),
|
||||
"serviceType": auth_token.serviceType,
|
||||
"client": auth_token.client,
|
||||
"clientMessageId": message_id
|
||||
}
|
||||
# Check if the mail already exists in your database:
|
||||
mail_records = await self.get_message_previews(
|
||||
mongo_data_conn = mongo_data_conn,
|
||||
token_ids = [ObjectId(auth_token.authTokenId)],
|
||||
limit = 1,
|
||||
skip = 0,
|
||||
additional_filter = {
|
||||
"tokenId": ObjectId(auth_token.authTokenId),
|
||||
"serviceType": auth_token.serviceType,
|
||||
"client": auth_token.client,
|
||||
"clientMessageId": message_id
|
||||
}
|
||||
)
|
||||
if mail_records:
|
||||
sync_result.success = True
|
||||
sync_result.isNew = False
|
||||
sync_result.message = (
|
||||
f"Gmail message '{message_id}' already "
|
||||
f"sync'd on {mail_records[0].syncTs} (UTC)."
|
||||
)
|
||||
if mail_records:
|
||||
sync_result.success = True
|
||||
sync_result.message = (
|
||||
f"Gmail message '{message_id}' already "
|
||||
f"sync'd on {mail_records[0].syncTs} (UTC)."
|
||||
)
|
||||
print(sync_result)
|
||||
return sync_result
|
||||
|
||||
# If the mail already exists and we have not been asked to force-sync:
|
||||
if not sync_result.isNew and not force_sync: return sync_result
|
||||
|
||||
# Now that we know that we have to fetch the mail from GMail:
|
||||
sync_result.attempted = True
|
||||
client_response = await mail_client.get_message(
|
||||
tokens = google_tokens,
|
||||
message_id = message_id,
|
||||
@@ -660,8 +661,14 @@ class GmailController(MailController):
|
||||
sync_results.totalCount = len(individual_sync_results)
|
||||
mongo_operations = []
|
||||
for result in individual_sync_results:
|
||||
if result.success: sync_results.successCount += 1
|
||||
else: sync_results.failureCount += 1
|
||||
|
||||
# Maintain the result counters:
|
||||
if result.attempted:
|
||||
if result.success: sync_results.successCount += 1
|
||||
else: sync_results.failureCount += 1
|
||||
if result.isNew: sync_results.newCount += 1
|
||||
|
||||
# Create the database requests:
|
||||
if result.mailMessage:
|
||||
replacement_json = result.mailMessage.model_dump()
|
||||
replacement_json.pop("_id", None)
|
||||
@@ -678,7 +685,7 @@ class GmailController(MailController):
|
||||
)
|
||||
)
|
||||
|
||||
# Make the bulk insert operation:
|
||||
# Make the bulk operation:
|
||||
if mongo_operations:
|
||||
sync_count = await self.bulk_operate_messages(
|
||||
mongo_data_conn = mongo_data_conn,
|
||||
|
||||
Reference in New Issue
Block a user