Meteor-Community-Packages / mongo-collection-instances

🗂 Meteor package allowing Mongo Collection instance lookup by collection name

Home Page:http://packosphere.com/dburles/mongo-collection-instances

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Structure and search speed

ivansglazunov opened this issue · comments

I have more than 50 collections. Loop through all of them to achieve the desired - it is impossible long.

I want to offer a better version.

Now the storage structure:

var instances = [Mongo.Collection,Mongo.Collection,Mongo.Collection,Mongo.Collection,Mongo.Collection];

Cycle of> 50 items.

Proposed structure:

var namedInstances = {
    posts: [Mongo.Collection,Mongo.Collection],
    users: [Mongo.Collection],
    links: [Mongo.Collection, Mongo.Collection]
};
var nullInstances = [Mongo.Collection,Mongo.Collection];

One condition + cycle of 1-2-3 items.

It is only necessary to register separately null-collection named-collections.

If the authors agree, I'll be glad to do pull-request.

Hey I'm not quite sure what you're asking for here? You seem to have many collections that share the same name?

No collections have different names.
Source code in this package
lodash.find heavy enough operation.
Mongo.Collection.get calls at me 2 times for each query to the database.
This means 2 cycles * 50 items = ~50-100 function calls.
If the storage structure change can be obtained 2 if + 2 cycles * 1-3 items = 2-6 function calls.
It looks better?

If no duplicate names then possible to do without cycles.

Oh I see what you're saying, yeah that makes sense, happy for you to provide a PR