Skip to content

Commit

Permalink
Merge pull request #840 from veliovgroup/dev
Browse files Browse the repository at this point in the history
📦 v2.1.1
  • Loading branch information
dr-dimitru authored Jun 9, 2022
2 parents 1a908d3 + 8aae4aa commit 6573b59
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .versions
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'ostrio:files',
version: '2.1.0',
version: '2.1.1',
summary: 'Upload files to Meteor application, with 3rd party storage support: AWS:S3, GridFS and other',
git: 'https://github.com/veliovgroup/Meteor-Files',
documentation: 'README.md'
Expand Down
49 changes: 48 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,53 @@ import nodePath from 'path';
const bound = Meteor.bindEnvironment(callback => callback());
const noop = function noop () {};

/**
* Create (ensure) index on MongoDB collection, catch and log exception if thrown
* @function createIndex
* @param {Mongo.Collection} collection - Mongo.Collection instance
* @param {object} keys - Field and value pairs where the field is the index key and the value describes the type of index for that field
* @param {object} opts - Set of options that controls the creation of the index
* @returns {void 0}
*/
const createIndex = async (collection, keys, opts) => {
try {
await collection.rawCollection().createIndex(keys, opts);
} catch (e) {
if (e.code === 85) {
let indexName;
const indexes = await collection.rawCollection().indexes();
for (const index of indexes) {
let allMatch = true;
for (const indexKey of Object.keys(keys)) {
if (typeof index.key[indexKey] === 'undefined') {
allMatch = false;
break;
}
}

for (const indexKey of Object.keys(index.key)) {
if (typeof keys[indexKey] === 'undefined') {
allMatch = false;
break;
}
}

if (allMatch) {
indexName = index.name;
break;
}
}

if (indexName) {
await collection.rawCollection().dropIndex(indexName);
await collection.rawCollection().createIndex(keys, opts);
}
} else {
Meteor._debug(`Can not set ${Object.keys(keys).join(' + ')} index on "${collection._name}" collection`, { keys, opts, details: e });
}
}
};

/**
* @locus Anywhere
* @class FilesCollection
Expand Down Expand Up @@ -336,7 +383,7 @@ export class FilesCollection extends FilesCollectionCore {
}
check(this._preCollectionName, String);

this._preCollection.createIndex({ createdAt: 1 }, { expireAfterSeconds: this.continueUploadTTL, background: true });
createIndex(this._preCollection, { createdAt: 1 }, { expireAfterSeconds: this.continueUploadTTL, background: true });
const _preCollectionCursor = this._preCollection.find({}, {
fields: {
_id: 1,
Expand Down

0 comments on commit 6573b59

Please sign in to comment.