diff --git a/inbox/mailsync/backends/gmail.py b/inbox/mailsync/backends/gmail.py index a5fe5b5d8..eda77d293 100644 --- a/inbox/mailsync/backends/gmail.py +++ b/inbox/mailsync/backends/gmail.py @@ -20,6 +20,7 @@ """ +import itertools from collections import OrderedDict from datetime import datetime, timedelta from threading import Semaphore @@ -295,8 +296,9 @@ def initial_sync_impl(self, crispin_client: "CrispinClient") -> None: ) ) - uids_to_download = sorted(unknown_uids - inbox_uids) + sorted( - unknown_uids & inbox_uids + uids_to_download = itertools.chain( + reversed(unknown_uids & inbox_uids), + reversed(unknown_uids - inbox_uids), ) del inbox_uids # free up memory as soon as possible @@ -305,7 +307,7 @@ def initial_sync_impl(self, crispin_client: "CrispinClient") -> None: del unknown_uids # free up memory as soon as possible - for uids in chunk(reversed(uids_to_download), 1024): + for uids in chunk(uids_to_download, 1024): g_metadata = crispin_client.g_metadata(uids) # UIDs might have been expunged since sync started, in which # case the g_metadata call above will return nothing.