Session: How to Perform Operations Lazily

Operation execution for operations such as load, load with includes, loadStartingWith and queries can be deferred till needed using lazy session operations. Those operations can be accessed using lazily() property found in advanced session operations.

Operations

Available operations are:

  • load - described here.
  • load with includes - described here.
  • loadStartingWith - described here.

Querying

Dedicated article about lazy queries can be found here.

Example

const employeeLazy = session
    .advanced
    .lazily
    .load("employees/1-A");

const employee = await employeeLazy.getValue(); // load operation will be executed here

Executing All Pending Lazy Operations

To execute all pending lazy operations use executeAllPendingLazyOperations() method from eager session operations found under eagerly property in advanced session operations.

const employeesLazy = session
    .query({ collection: "Employees" })
    .lazily();

await session.advanced.eagerly.executeAllPendingLazyOperations(); // query will be executed here

const employees = await employeesLazy.getValue();