mailcrunch/deployment — pull request #11 by Jygsaw (2014-07-25 19:31:04+00:00)
Title: (fix) Infinite load after all emails sorted but not crunched

Description:
The loading emails page (four moving dots) never stops loading when a user has sorted all of their emails but has not finished crunching them.

Problem:
The logic to close the IMAP session is embedded in the logic to pull "unsorted" emails from the DB. When there are no "unseen" emails, the app will handle the edge case and close the IMAP session. However, when Google still considers an email "unseen", the app will initiate an IMAP session and never close the session. This behavior is because the logic to close the session only fires when the DB returns "unsorted" emails and all emails at this point have been sorted.

Test Case:
1) User logs in to sort new messages
2) User sorts all messages and proceeds to crunch phase
3) Crunch phase is interrupted'
- User has no time currently
- Computer/Internet crashes
- etc.
4) User returns to site and clicks "Start a sort session" on home profile page
5) Verify loading screen never finishes