mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-10-05 11:24:51 +08:00
enable zlib for message collections
This commit is contained in:
parent
ef774cf809
commit
f7cb3c1d17
2 changed files with 80 additions and 21 deletions
77
imap.js
77
imap.js
|
@ -16,7 +16,7 @@ const packageData = require('./package.json');
|
||||||
const yaml = require('js-yaml');
|
const yaml = require('js-yaml');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const certs = require('./lib/certs').get('imap');
|
const certs = require('./lib/certs').get('imap');
|
||||||
const setupIndexes = yaml.safeLoad(fs.readFileSync(__dirname + '/indexes.yaml', 'utf8')).indexes;
|
const setupIndexes = yaml.safeLoad(fs.readFileSync(__dirname + '/indexes.yaml', 'utf8'));
|
||||||
|
|
||||||
const onFetch = require('./lib/handlers/on-fetch');
|
const onFetch = require('./lib/handlers/on-fetch');
|
||||||
const onAuth = require('./lib/handlers/on-auth');
|
const onAuth = require('./lib/handlers/on-auth');
|
||||||
|
@ -309,19 +309,52 @@ module.exports = done => {
|
||||||
server.onGetQuota = onGetQuota(server);
|
server.onGetQuota = onGetQuota(server);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let collections = setupIndexes.collections;
|
||||||
|
let collectionpos = 0;
|
||||||
|
let ensureCollections = next => {
|
||||||
|
if (collectionpos >= collections.length) {
|
||||||
|
server.logger.info(
|
||||||
|
{
|
||||||
|
tnx: 'mongo'
|
||||||
|
},
|
||||||
|
'Setup %s collections',
|
||||||
|
collections.length
|
||||||
|
);
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
let collection = collections[collectionpos++];
|
||||||
|
db[collection.type || 'database'].createCollection(collection.collection, collection.options, err => {
|
||||||
|
if (err) {
|
||||||
|
server.logger.error(
|
||||||
|
{
|
||||||
|
err,
|
||||||
|
tnx: 'mongo'
|
||||||
|
},
|
||||||
|
'Failed creating collection %s %s. %s',
|
||||||
|
collectionpos,
|
||||||
|
JSON.stringify(collection.collection),
|
||||||
|
err.message
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ensureCollections(next);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
let indexes = setupIndexes.indexes;
|
||||||
let indexpos = 0;
|
let indexpos = 0;
|
||||||
let ensureIndexes = next => {
|
let ensureIndexes = next => {
|
||||||
if (indexpos >= setupIndexes.length) {
|
if (indexpos >= indexes.length) {
|
||||||
server.logger.info(
|
server.logger.info(
|
||||||
{
|
{
|
||||||
tnx: 'mongo'
|
tnx: 'mongo'
|
||||||
},
|
},
|
||||||
'Setup indexes for %s collections',
|
'Setup indexes for %s collections',
|
||||||
setupIndexes.length
|
indexes.length
|
||||||
);
|
);
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
let index = setupIndexes[indexpos++];
|
let index = indexes[indexpos++];
|
||||||
db[index.type || 'database'].collection(index.collection).createIndexes([index.index], (err, r) => {
|
db[index.type || 'database'].collection(index.collection).createIndexes([index.index], (err, r) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
server.logger.error(
|
server.logger.error(
|
||||||
|
@ -374,23 +407,25 @@ module.exports = done => {
|
||||||
return start();
|
return start();
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureIndexes(() => {
|
ensureCollections(() => {
|
||||||
// Do not release the indexing lock immediatelly
|
ensureIndexes(() => {
|
||||||
setTimeout(() => {
|
// Do not release the indexing lock immediatelly
|
||||||
gcLock.releaseLock(lock, err => {
|
setTimeout(() => {
|
||||||
if (err) {
|
gcLock.releaseLock(lock, err => {
|
||||||
server.logger.error(
|
if (err) {
|
||||||
{
|
server.logger.error(
|
||||||
tnx: 'gc',
|
{
|
||||||
err
|
tnx: 'gc',
|
||||||
},
|
err
|
||||||
'Failed to release lock error=%s',
|
},
|
||||||
err.message
|
'Failed to release lock error=%s',
|
||||||
);
|
err.message
|
||||||
}
|
);
|
||||||
});
|
}
|
||||||
}, 60 * 1000);
|
});
|
||||||
return start();
|
}, 60 * 1000);
|
||||||
|
return start();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
24
indexes.yaml
24
indexes.yaml
|
@ -1,4 +1,28 @@
|
||||||
---
|
---
|
||||||
|
collections:
|
||||||
|
|
||||||
|
# create following collections with specific options
|
||||||
|
|
||||||
|
- collection: messages
|
||||||
|
options:
|
||||||
|
storageEngine:
|
||||||
|
wiredTiger:
|
||||||
|
configString: block_compressor=zlib
|
||||||
|
|
||||||
|
- collection: attachments.files
|
||||||
|
type: gridfs
|
||||||
|
options:
|
||||||
|
storageEngine:
|
||||||
|
wiredTiger:
|
||||||
|
configString: block_compressor=zlib
|
||||||
|
|
||||||
|
- collection: attachments.chunks
|
||||||
|
type: gridfs
|
||||||
|
options:
|
||||||
|
storageEngine:
|
||||||
|
wiredTiger:
|
||||||
|
configString: block_compressor=zlib
|
||||||
|
|
||||||
indexes:
|
indexes:
|
||||||
|
|
||||||
# Indexes for the user collection
|
# Indexes for the user collection
|
||||||
|
|
Loading…
Add table
Reference in a new issue