elie222 / inbox-zero

Open source email app to reach inbox zero fast.
https://getinboxzero.com
GNU Affero General Public License v3.0
2.53k stars 258 forks source link

POC for Bulk archive using Action queue #87

Closed Ipriyankrajai closed 8 months ago

Ipriyankrajai commented 8 months ago

Previous conversation here: https://github.com/elie222/inbox-zero/pull/86

POC for better management of bulk tasks.

Motivation

We can get rate limited on the OpenAI API or the Google API. Using p-queue we can limit bulk actions to 1 at a time. Ro 3 at a time. And make sure we're below any rate limit thresholds (and also retry failed tasks).

Would likely also clean up the codebase a bunch. We could use the same mechanism for bulk and single actions.

Usage

Would be used like so:

const queue = useQueue()

<button
  onClick={() => 
    queue.archiveEmails(['thread1', 'thread2']) // could also just be one thread if it's not a bulk action
  }>
  Archive
</button>

Loading State

Probably also want to store the state of a task. So that we know that thread1 and thread2 are isArchiving: true. So if we need to show a spinner for a certain row in the UI we can do that. A simple Zustand store might work for this. Reason we'd use Zustand over React Context is that only specific email rows would need to update. With React Context everything would update whenever the store changes. Although could maybe deal with this optimisation later too, and just have a simple useState for it to begin with.

Calling Gmail from Client vs Server

ATM, we're calling our server which calls the Gmail API. But really we could call the Gmail API directly if the client has the access token. It's inefficient to call the server API and we'd get faster responses if we called Gmail directly. For archiving an email there's no reason for it to route through our backend. The change will likely be minimal as this code calls server functions, and calling client actions will be the same thing. But I put this here as part of the larger direction to keep in mind. Even if not implementing it today.

vercel[bot] commented 8 months ago

@Ipriyankrajai is attempting to deploy a commit to the Inbox Zero Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] commented 8 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
inbox-zero ✅ Ready (Inspect) Visit Preview Jan 10, 2024 5:05pm
elie222 commented 8 months ago

Merge conflict which I fixed here: https://github.com/elie222/inbox-zero/pull/86

elie222 commented 8 months ago

Ah. I see it's only sitemap now

elie222 commented 8 months ago

Merged here: https://github.com/elie222/inbox-zero/pull/103