cult-of-coders / grapher

Grapher: Meteor Collection Joins + Reactive GraphQL like queries
https://atmospherejs.com/cultofcoders/grapher
MIT License
275 stars 53 forks source link

query.fetchOne() fetches all results instead of using limit: 1 #446

Closed Floriferous closed 2 years ago

Floriferous commented 3 years ago

We noticed some serious performance issues because of how Query.fetchOne is implemented:

https://github.com/cult-of-coders/grapher/blob/842dbb1ed313ecd1abdd7fc79378be673445df1b/lib/query/query.server.js#L26

    fetchOne(...args) {
        return _.first(this.fetch(...args));
    }

You would assume that it limits the amount of results returned from the DB, but instead it returns all the results with fetch before taking the first result out of it.

In our case, we simply wanted the most recent document out of a collection, and we noticed that it returned the entire collection from the DB!!