Skip to content

Add MongoCollection wrapper and move few basic uses of collection to it. #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 2, 2016

Conversation

nlutsenko
Copy link
Contributor

Adds MongoCollection wrapper class that will be used as a replacement for direct mongo drive collection access.
Also, moved few basic things that interact with the collection directly to this new API.

As you can see - we can already move custom indexing logic into MongoCollection, since it's super specific to mongo.
The next steps:

  • replace all usages of database.collection() to database.adaptiveCollection() adding the APIs where we need
  • Move transformation logic for find/update/insert directly into MongoCollection
  • ...
  • PROFIT!

//TODO: condiser moving index creation logic into Schema.js
return this._mongoCollection.createIndex(index)
// Retry, but just once.
.then(() => this.find(query, { skip, limit, sort }));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike the old implementation, this doesn't seem to have any logic to avoid retrying infinitely if you get the same error over and over. I don't see how that could happen if the index build succeeded, but maybe it's worth it to keep that logic around anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call actually, let me change this a tiny bit then to accommodate for this.

@nlutsenko nlutsenko force-pushed the nlutsenko.adapter.collection branch from a622a18 to 9538a7d Compare March 2, 2016 06:36
//TODO: condiser moving index creation logic into Schema.js
return this._mongoCollection.createIndex(index)
// Retry, but just once.
.then(() => this._rawFind(query, { skip, limit, sort }));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Everything going to go through a private method now, which will retry find just once.

@facebook-github-bot
Copy link

@nlutsenko updated the pull request.

return req.config.database.adaptiveCollection('_SCHEMA')
.then(collection => collection.find({}))
.then(schemas => schemas.map(mongoSchemaToSchemaAPIResponse))
.then(schemas => ({ response: { results: schemas }}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting this in a separate then is actually marginally slower than not doing so, because each then callback happens in a separate turn of the event loop. Very minor difference, but I thought you might want to know (if you end up contributing to the dashboard at all, avoiding extraneous thens is a bigger deal because doing too many can cause a re-render on each turn of the event loop)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(y) That makes sense.
Do you want me to change it here? It is soo beautiful with an extra then :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it is a very small perf impact, so I don't think it really matters. In the dashboard I would ask you to change it :p

@drew-gross
Copy link
Contributor

A couple optional things. Feel free to ignore them.

nlutsenko added a commit that referenced this pull request Mar 2, 2016
Add MongoCollection wrapper and move few basic uses of collection to it.
@nlutsenko nlutsenko merged commit 4fe670e into master Mar 2, 2016
@nlutsenko nlutsenko deleted the nlutsenko.adapter.collection branch March 2, 2016 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants