Skip to content

Commit

Permalink
fix: fixed SEARCH and storage quota (due to new sync setup with tmp f…
Browse files Browse the repository at this point in the history
…ile)
  • Loading branch information
titanism committed Jun 27, 2024
1 parent 48e0bf1 commit 377addc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const STRIPE_LOCALES = new Set([

const config = {
...metaConfig,
INITIAL_DB_SIZE: 200704,
INITIAL_DB_SIZE: 196608, // 200704,
STRIPE_LOCALES,
openPGPKey: '/.well-known/openpgpkey/hu/mxqp8ogw4jfq83a58pn1wy1ccc1cx3f5.asc',
returnPath: 'fe-bounces',
Expand Down
21 changes: 15 additions & 6 deletions helpers/imap/on-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,14 @@ async function onSearch(mailboxId, options, session, fn) {
for (const id of ids) {
set.add(id);
}

// old approach:
// parent.push({
// _id: { $in: ids }
// });
parent.push({
_id: { $ne: '' }
});

// NOTE: this is the wildduck reference (which does not support NOT matches)
// search over email body
Expand Down Expand Up @@ -322,8 +326,10 @@ async function onSearch(mailboxId, options, session, fn) {
for (const id of ids) {
set.add(id);
}

// old approach:
// entry._id = { $in: ids };
entry._id = { $ne: '' };
} else {
const sql = {
// NOTE: for array lookups:
Expand All @@ -341,8 +347,10 @@ async function onSearch(mailboxId, options, session, fn) {
for (const id of ids) {
set.add(id);
}

// old approach:
// entry._id = { $in: ids };
entry._id = { $ne: '' };
}
} else if (ne) {
const sql = {
Expand All @@ -362,6 +370,7 @@ async function onSearch(mailboxId, options, session, fn) {

// old approach
// entry._id = { $in: ids };
entry._id = { $ne: '' };
} else {
const sql = {
query: `select _id from Messages, json_each(Messages.headers) where key = $p1;`,
Expand All @@ -380,6 +389,7 @@ async function onSearch(mailboxId, options, session, fn) {

// old approach
// entry._id = { $in: ids };
entry._id = { $ne: '' };
}

// wildduck/mongodb version
Expand Down Expand Up @@ -623,15 +633,14 @@ async function onSearch(mailboxId, options, session, fn) {
type: 'select',
table: 'Messages',
condition,
fields: ['uid', 'modseq']
fields: ['_id', 'uid', 'modseq']
});

//
// NOTE: using `all()` currently for faster performance
// (since we don't write to the socket here)
//

try {
//
// NOTE: using `all()` currently for faster performance
// (since we don't write to the socket here)
//
// const messages = session.db.prepare(sql.query).all(sql.values);
// for (const message of messages) {
// // SQLITE_MAX_VARIABLE_NUMBER which defaults to 999
Expand Down
4 changes: 2 additions & 2 deletions test/imap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ test('onGetQuotaRoot', async (t) => {
t.is(quota.storage.status, '0%');
t.log('quota', quota);
t.log('quota.storage.usage', quota.storage.usage);
t.is(quota.storage.usage, 196608);
t.is(quota.storage.usage, 188416);
// TODO: figure out why config.INITIAL_DB_SIZE is sometimes off here (e.g. its sometimes 200704)
// t.deepEqual(quota, {
// path: 'INBOX',
Expand Down Expand Up @@ -1640,7 +1640,7 @@ ${randomString}`.trim()
await imapFlow.append('INBOX', raw, [], new Date());

const storageUsed = await Aliases.getStorageUsed(alias);
t.is(storageUsed, 101208064);
t.is(storageUsed, 101081088); // 101208064);

mailbox = await Mailboxes.findById(
t.context.imap,
Expand Down

0 comments on commit 377addc

Please sign in to comment.