marklogic-community / marklogic-state-conductor

An event-based state-machine engine for manipulating MarkLogic database documents.
Other
1 stars 4 forks source link

Utilize aggregate functions in getStateMachineCounts function #158

Closed aclavio closed 3 years ago

aclavio commented 3 years ago

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)
        )
      )
    );
aclavio commented 3 years ago

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'
    );