Skip to content

Commit 2c29161

Browse files
committed
fix: stagger IMAP startup connections; remove in-CI version bump that mutated main
1 parent d483ad3 commit 2c29161

2 files changed

Lines changed: 10 additions & 19 deletions

File tree

‎.github/workflows/publish.yml‎

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- 'v*.*.*'
77

88
permissions:
9-
contents: write
9+
contents: read
1010
packages: write
1111

1212
jobs:
@@ -23,18 +23,6 @@ jobs:
2323
- name: Set up Docker Buildx
2424
uses: docker/setup-buildx-action@v3
2525

26-
- name: Bump package.json versions
27-
run: |
28-
VERSION="${{ github.ref_name }}"
29-
VERSION="${VERSION#v}"
30-
jq --arg v "$VERSION" '.version = $v' backend/package.json > /tmp/pkg.json && mv /tmp/pkg.json backend/package.json
31-
jq --arg v "$VERSION" '.version = $v' frontend/package.json > /tmp/pkg.json && mv /tmp/pkg.json frontend/package.json
32-
git config user.name "github-actions[bot]"
33-
git config user.email "github-actions[bot]@users.noreply.github.com"
34-
git add backend/package.json frontend/package.json
35-
git diff --cached --quiet || git commit -m "chore: bump version to ${VERSION}"
36-
git push origin HEAD:main
37-
3826
- name: Log in to GHCR
3927
uses: docker/login-action@v3
4028
with:

‎backend/src/index.js‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,20 @@ await loadIntegrationConfigs();
155155
// Start background snooze watcher — polls every 60 seconds to restore snoozed messages
156156
imapManager.startSnoozeWatcher();
157157

158-
// Re-connect all enabled IMAP accounts on startup so mail syncs immediately
159-
// even before any WebSocket client connects (covers cold-start and container restarts)
158+
// Re-connect all enabled IMAP accounts on startup, staggered 500 ms apart so a
159+
// large user base doesn't hammer IMAP servers and the DB connection pool at once.
160160
try {
161161
const startupResult = await query(
162162
"SELECT DISTINCT user_id FROM email_accounts WHERE enabled = true AND protocol = 'imap'"
163163
);
164-
for (const row of startupResult.rows) {
165-
imapManager.connectAllForUser(row.user_id).catch(err =>
166-
console.error(`Startup connect failed for user ${row.user_id}:`, err.message)
164+
startupResult.rows.forEach(({ user_id }, i) => {
165+
setTimeout(
166+
() => imapManager.connectAllForUser(user_id).catch(err =>
167+
console.error(`Startup connect failed for user ${user_id}:`, err.message)
168+
),
169+
i * 500,
167170
);
168-
}
171+
});
169172
if (startupResult.rows.length) {
170173
console.log(`Reconnecting accounts for ${startupResult.rows.length} user(s) on startup`);
171174
}

0 commit comments

Comments
 (0)