marklogic-community/marklogic-state-conductor

Utilize aggregate functions in getStateMachineCounts function

Closed this issue · 1 comments

Switch from fn.count based approach in the getStateMachineCounts function to utilizing the cts.countAggregate() calculation. This is much more performant on large datasets.

eg:

const numInState = (status, state) =>
    cts.countAggregate(
      cts.uriReference(),
      null,
      cts.andQuery(
        [].concat(
          baseQuery,
          cts.jsonPropertyValueQuery('name', name),
          cts.jsonPropertyValueQuery('status', status),
          cts.jsonPropertyValueQuery('state', state)
        )
      )
    );

Also investigate if cts.estimate would be accurate enough and performant.

eg:

const numInStateEst = (status, state) =>
    cts.estimate(
      cts.andQuery(
        [].concat(
          baseQuery,
          cts.jsonPropertyValueQuery('name', name),
          cts.jsonPropertyValueQuery('status', status),
          cts.jsonPropertyValueQuery('state', state)
        )
      ),
      'document'
    );