mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-12-27 10:21:11 +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 fs = require('fs');
|
||||
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 onAuth = require('./lib/handlers/on-auth');
|
||||
|
@ -309,19 +309,52 @@ module.exports = done => {
|
|||
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 ensureIndexes = next => {
|
||||
if (indexpos >= setupIndexes.length) {
|
||||
if (indexpos >= indexes.length) {
|
||||
server.logger.info(
|
||||
{
|
||||
tnx: 'mongo'
|
||||
},
|
||||
'Setup indexes for %s collections',
|
||||
setupIndexes.length
|
||||
indexes.length
|
||||
);
|
||||
return next();
|
||||
}
|
||||
let index = setupIndexes[indexpos++];
|
||||
let index = indexes[indexpos++];
|
||||
db[index.type || 'database'].collection(index.collection).createIndexes([index.index], (err, r) => {
|
||||
if (err) {
|
||||
server.logger.error(
|
||||
|
@ -374,23 +407,25 @@ module.exports = done => {
|
|||
return start();
|
||||
}
|
||||
|
||||
ensureIndexes(() => {
|
||||
// Do not release the indexing lock immediatelly
|
||||
setTimeout(() => {
|
||||
gcLock.releaseLock(lock, err => {
|
||||
if (err) {
|
||||
server.logger.error(
|
||||
{
|
||||
tnx: 'gc',
|
||||
err
|
||||
},
|
||||
'Failed to release lock error=%s',
|
||||
err.message
|
||||
);
|
||||
}
|
||||
});
|
||||
}, 60 * 1000);
|
||||
return start();
|
||||
ensureCollections(() => {
|
||||
ensureIndexes(() => {
|
||||
// Do not release the indexing lock immediatelly
|
||||
setTimeout(() => {
|
||||
gcLock.releaseLock(lock, err => {
|
||||
if (err) {
|
||||
server.logger.error(
|
||||
{
|
||||
tnx: 'gc',
|
||||
err
|
||||
},
|
||||
'Failed to release lock error=%s',
|
||||
err.message
|
||||
);
|
||||
}
|
||||
});
|
||||
}, 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 for the user collection
|
||||
|
|
Loading…
Reference in a new issue