Short-circuit in _choose_existing_thread_for_gmail.

This avoids an unecessarily expensive lazy load in the common case that there's
exactly one prior thread.
Optimize IMAP update_metadata function.

Summary:
recompute_thread_labels() proves to be a relatively expensive function. The
problem with this is that in generic IMAP sync, we refetch flags for up to
refresh_flags_max=2000 UIDs, and recompute thread labels for each associated
thread, even if there weren't actually any changes. This turns out to be really
expensive in CPU time and query volume.

Instead, check if there are actual flag changes. In the process, rename
`ImapUid.update_imap_flags` to `ImapUid.update_flags_and_labels ` for clarity,
and clean up the relevant code a bit.

Test Plan: Unit tests.

Reviewers: spang

Reviewed By: spang

Differential Revision: https://review.inboxapp.com/D926