<commit_before>'use strict';

// An QueryRequest is used to represent a RethinkDB query that a component is
// subscribed to. It should be used for values in the object returned from the
// observe() function of components that use the provided mixin. See Mixin.js
// for the API.
//
// QueryRequests have have 3 required properties.
// * query:   the RethinkDB query to run
// * changes: boolean specifying whether to subscribe to the realtime
//            changefeed too
// * initial: value to be returned before the query finishes loading
//
// Here is a simple example of an QueryRequest that a component might use in
// its observe() function:
//   new QueryRequest({
//     query: r.table('turtles'),
//     changes: true,
//     initial: [],
//   })
export class QueryRequest {
  constructor({query, changes, initial}) {
    this.query = query;
    this.changes = changes;
    this.initial = initial;
  }

  // Convert the QueryRequest into a string that can be used as a
  // deterministic lookup key in an object. The key should be identical for two
  // QueryRequests that need access to the same data.
  //
  // TODO We should recursively sort object keys, using something like
  // json-stable-stringify. But let's do that for query validation in
  // rethinkdb-websocket-server first, after confirming that object sort order is
  // ignored in RethinkDB.
  //
  // TODO This isn't perfectly deterministic for queries with anonymous
  // functions, since the variable identifier keeps incrementing when we create
  // new "identical" queries.
  // E.g. r.table('turtles').filter(x => x('herdId').eq(props.herdId))
  toStringKey() {
    return JSON.stringify({
      query: this.query.build(),
      changes: this.changes,
    });
  }
}<commit_msg>Comment more on queries with anonymous functions<commit_after>'use strict';

// An QueryRequest is used to represent a RethinkDB query that a component is
// subscribed to. It should be used for values in the object returned from the
// observe() function of components that use the provided mixin. See Mixin.js
// for the API.
//
// QueryRequests have have 3 required properties.
// * query:   the RethinkDB query to run
// * changes: boolean specifying whether to subscribe to the realtime
//            changefeed too
// * initial: value to be returned before the query finishes loading
//
// Here is a simple example of an QueryRequest that a component might use in
// its observe() function:
//   new QueryRequest({
//     query: r.table('turtles'),
//     changes: true,
//     initial: [],
//   })
export class QueryRequest {
  constructor({query, changes, initial}) {
    this.query = query;
    this.changes = changes;
    this.initial = initial;
  }

  // Convert the QueryRequest into a string that can be used as a
  // deterministic lookup key in an object. The key should be identical for two
  // QueryRequests that need access to the same data.
  //
  // TODO We should recursively sort object keys, using something like
  // json-stable-stringify. But let's do that for query validation in
  // rethinkdb-websocket-server first, after confirming that object sort order is
  // ignored in RethinkDB.
  //
  // TODO This isn't perfectly deterministic for queries with anonymous
  // functions, since the variable identifier keeps incrementing when we create
  // new "identical" queries.
  // E.g. r.table('turtles').filter(x => x('herdId').eq(props.herdId))
  // It looks like the RethinkDB JavaScript driver has to maintain a global
  // nextVarId counter which can increment between the creation of identical
  // queries. This is probably necessary so that queries that contain multiple
  // functions won't have overlapping var ids. One possible approach is to
  // "normalize" var ids as a query preprocessing step: replace each var id
  // with an index in which that var id was first seen in the query. Further
  // research needs to be done to determine if that is safe.  This approach has
  // a disadvantage of being harder to debug query issues when queries are
  // being altered.
  toStringKey() {
    return JSON.stringify({
      query: this.query.build(),
      changes: this.changes,
    });
  }
}
{'fraction_non_alphanumeric': 0.08997613365155131, 'fraction_numerical': 0.00047732696897374703, 'mean_word_length': 3.0336862367661213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5068833', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1084, 'n_words': 521}