elie222 / inbox-zero

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

WIP: bulk action queue #86

Closed elie222 closed 5 months ago

elie222 commented 6 months ago

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 6 months ago

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

Name Status Preview Comments Updated (UTC)
inbox-zero ❌ Failed (Inspect) Jan 19, 2024 9:26pm
inbox-zero-react-email ❌ Failed (Inspect) Jan 19, 2024 9:26pm
elie222 commented 5 months ago

Closing this PR as @Ipriyankrajai opened another one for it.