mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-07 13:14:47 +08:00
[client-sync] Also prioritize sent label for initial Gmail sync
Summary: Sent mail is important for initial sync because it's used for contact ranking. Prior to this diff we would delay syncing sent mail because we would prioritize the inbox label over all other labels (including sent). This diff includes the sent folder in the initial set of messages to sync. Test Plan: Run locally, verify we get sent mail quickly Reviewers: evan, spang, juan Reviewed By: spang Differential Revision: https://phab.nylas.com/D4268
This commit is contained in:
parent
da018c3639
commit
d6a2b6935c
1 changed files with 17 additions and 15 deletions
|
@ -10,7 +10,7 @@ const FETCH_ATTRIBUTES_BATCH_SIZE = 1000;
|
||||||
const MIN_MESSAGE_BATCH_SIZE = 30;
|
const MIN_MESSAGE_BATCH_SIZE = 30;
|
||||||
const MAX_MESSAGE_BATCH_SIZE = 300;
|
const MAX_MESSAGE_BATCH_SIZE = 300;
|
||||||
const BATCH_SIZE_PER_SELECT_SEC = 60;
|
const BATCH_SIZE_PER_SELECT_SEC = 60;
|
||||||
const GMAIL_INBOX_PRIORITIZE_COUNT = 1000;
|
const GMAIL_INITIAL_PRIORITIZE_COUNT = 1000;
|
||||||
|
|
||||||
|
|
||||||
class FetchMessagesInFolderIMAP extends SyncTask {
|
class FetchMessagesInFolderIMAP extends SyncTask {
|
||||||
|
@ -381,29 +381,31 @@ class FetchMessagesInFolderIMAP extends SyncTask {
|
||||||
async * _fetchFirstUnsyncedMessages(batchSize) {
|
async * _fetchFirstUnsyncedMessages(batchSize) {
|
||||||
const {provider} = this._account;
|
const {provider} = this._account;
|
||||||
const folderRole = this._folder.role;
|
const folderRole = this._folder.role;
|
||||||
const gmailInboxUIDsRemaining = this._folder.syncState.gmailInboxUIDsRemaining;
|
// TODO: In a few releases, simplify this code to remove the
|
||||||
const gmailInboxUIDsUnset = !gmailInboxUIDsRemaining;
|
// gmailInboxUIDsRemaining after most people have been migrated.
|
||||||
const hasGmailInboxUIDsRemaining = gmailInboxUIDsRemaining && gmailInboxUIDsRemaining.length
|
const gmailInitialUIDsRemaining = this._folder.syncState.gmailInitialUIDsRemaining || this._folder.syncState.gmailInboxUIDsRemaining;
|
||||||
|
const gmailInitialUIDsUnset = !gmailInitialUIDsRemaining;
|
||||||
|
const hasGmailInboxUIDsRemaining = gmailInitialUIDsRemaining && gmailInitialUIDsRemaining.length
|
||||||
let totalProcessedMessages = 0;
|
let totalProcessedMessages = 0;
|
||||||
if (provider === "gmail" && folderRole === "all" && (gmailInboxUIDsUnset || hasGmailInboxUIDsRemaining)) {
|
if (provider === "gmail" && folderRole === "all" && (gmailInitialUIDsUnset || hasGmailInboxUIDsRemaining)) {
|
||||||
// Track the first few UIDs in the inbox label & download these first.
|
// Track the first few UIDs in the inbox label & download these first.
|
||||||
// If the user restarts the app before all these UIDs are downloaded & we
|
// If the user restarts the app before all these UIDs are downloaded & we
|
||||||
// also pass the UID in the All Mail folder range downloads we will
|
// also pass the UID in the All Mail folder range downloads we will
|
||||||
// redownload them, but that's OK.
|
// redownload them, but that's OK.
|
||||||
let inboxUids;
|
let initialUids;
|
||||||
if (!gmailInboxUIDsRemaining) {
|
if (!gmailInitialUIDsRemaining) {
|
||||||
// this._logger.log(`FetchMessagesInFolderIMAP: Fetching Gmail Inbox UIDs for prioritization`);
|
// this._logger.log(`FetchMessagesInFolderIMAP: Fetching Gmail Inbox UIDs for prioritization`);
|
||||||
inboxUids = await this._box.search([['X-GM-RAW', 'in:inbox']]);
|
initialUids = await this._box.search([['X-GM-RAW', 'in:inbox OR in:sent']]);
|
||||||
// Gmail always returns UIDs in order from smallest to largest, so this
|
// Gmail always returns UIDs in order from smallest to largest, so this
|
||||||
// gets us the most recent messages first.
|
// gets us the most recent messages first.
|
||||||
inboxUids = inboxUids.slice(Math.max(inboxUids.length - GMAIL_INBOX_PRIORITIZE_COUNT, 0));
|
initialUids = initialUids.slice(Math.max(initialUids.length - GMAIL_INITIAL_PRIORITIZE_COUNT, 0));
|
||||||
// Immediately persist to avoid issuing search again in case of interrupt
|
// Immediately persist to avoid issuing search again in case of interrupt
|
||||||
await this._folder.updateSyncState({
|
await this._folder.updateSyncState({
|
||||||
gmailInboxUIDsRemaining: inboxUids,
|
gmailInitialUIDsRemaining: initialUids,
|
||||||
fetchedmax: this._box.uidnext,
|
fetchedmax: this._box.uidnext,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
inboxUids = this._folder.syncState.gmailInboxUIDsRemaining;
|
initialUids = this._folder.syncState.gmailInitialUIDsRemaining;
|
||||||
}
|
}
|
||||||
// continue fetching new mail first in the case that inbox uid download
|
// continue fetching new mail first in the case that inbox uid download
|
||||||
// takes multiple batches
|
// takes multiple batches
|
||||||
|
@ -412,12 +414,12 @@ class FetchMessagesInFolderIMAP extends SyncTask {
|
||||||
this._logger.log(`🔃 📂 ${this._folder.name} new messages present; fetching ${fetchedmax}:${this._box.uidnext}`);
|
this._logger.log(`🔃 📂 ${this._folder.name} new messages present; fetching ${fetchedmax}:${this._box.uidnext}`);
|
||||||
totalProcessedMessages += yield this._fetchAndProcessMessages({min: fetchedmax, max: this._box.uidnext, throttle: false});
|
totalProcessedMessages += yield this._fetchAndProcessMessages({min: fetchedmax, max: this._box.uidnext, throttle: false});
|
||||||
}
|
}
|
||||||
const batchSplitIndex = Math.max(inboxUids.length - batchSize, 0);
|
const batchSplitIndex = Math.max(initialUids.length - batchSize, 0);
|
||||||
const uidsFetchNow = inboxUids.slice(batchSplitIndex);
|
const uidsFetchNow = initialUids.slice(batchSplitIndex);
|
||||||
const uidsFetchLater = inboxUids.slice(0, batchSplitIndex);
|
const uidsFetchLater = initialUids.slice(0, batchSplitIndex);
|
||||||
// this._logger.log(`FetchMessagesInFolderIMAP: Remaining Gmail Inbox UIDs to download: ${uidsFetchLater.length}`);
|
// this._logger.log(`FetchMessagesInFolderIMAP: Remaining Gmail Inbox UIDs to download: ${uidsFetchLater.length}`);
|
||||||
totalProcessedMessages += yield this._fetchAndProcessMessages({uids: uidsFetchNow, throttle: false});
|
totalProcessedMessages += yield this._fetchAndProcessMessages({uids: uidsFetchNow, throttle: false});
|
||||||
await this._folder.updateSyncState({ gmailInboxUIDsRemaining: uidsFetchLater });
|
await this._folder.updateSyncState({ gmailInitialUIDsRemaining: uidsFetchLater });
|
||||||
} else {
|
} else {
|
||||||
const lowerbound = Math.max(1, this._box.uidnext - batchSize);
|
const lowerbound = Math.max(1, this._box.uidnext - batchSize);
|
||||||
totalProcessedMessages += yield this._fetchAndProcessMessages({min: lowerbound, max: this._box.uidnext, throttle: false});
|
totalProcessedMessages += yield this._fetchAndProcessMessages({min: lowerbound, max: this._box.uidnext, throttle: false});
|
||||||
|
|
Loading…
Add table
Reference in a new issue