# All files / src/hacks watch-rewrites.js

50% Statements 2/4
57.14% Branches 4/7
100% Functions 1/1
50% Lines 2/4

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27

    45x

    45x

     /*
     Some common queries run on an entire collection or on a collection of
     indeterminate size. RethinkDB doesn't actually keep track of the
     ordering of these queries when sending changes. The initial changes
     will be ordered, but subsequent changes come in arbitrary order and
     don't respect the ordering of the query. So, for convenience, we add
     a very high limit so that the server will keep track of the order for
     us.

     Note: queries like collection.order(field).watch are not reasonable
     in production systems. You should add an explicit limit.
    */

    export default function watchRewrites(self, query) {
      // The only query type at the moment that doesn't get these rewrites
      // is find, since it returns a single document
      Iif (query.find === undefined &&
          query.order !== undefined &&
          query.limit === undefined) {
        const limit = self.constructor.IMPLICIT_LIMIT || 100000
        // Need to copy the object, since it could be reused
        return Object.assign({ limit }, query)
      } else {
        return query
      }
    }