I’m currently working on a web mail client. When a user logs in, I’m fetching all the mails from the INBOX from the beginning of time. As expected this is pretty darn slow. I’m planning to implement some sort of a filtering/caching technique and was looking for some ideas.
If I fetch all the message numbers, trim them and sort them in a descending order, will I have messages from the the last message received to the first? Also, would it be preferable to store mails in a intermediate database and fetch them from there?
Why don’t you reverse the order of your retrieval? Instead of starting at the beginning of time, start at the end of time (ie. most recent) and then go back in time.
Users looking at mail want to see what’s most recently come in, they don’t care as much about what was sent to them last week or even last year.
Another option to consider is an skip-take fetch process. Instead of waiting for everything to be fetched from the database.
- Retrieve the 20 most recent messages
- Return those to the client
- Get the next 20 most recent messages
- Return those to the client
- Repeat as needed
2