MCPcopy Create free account
hub / github.com/TanStack/db / getActiveAndLazySources

Function getActiveAndLazySources

packages/db/src/query/compiler/joins.ts:662–686  ·  view source on GitHub ↗

* Returns the active and lazy collections for a join clause. * The active collection is the one that we need to fully iterate over * and it can be the main source (i.e. left collection) or the joined source (i.e. right collection). * The lazy collection is the one that we should join-in lazily ba

(
  joinType: JoinClause[`type`],
  leftCollection: Collection,
  rightCollection: Collection,
)

Source from the content-addressed store, hash-verified

660 * @returns The active and lazy collections. They are undefined if we need to loop over both collections (i.e. both are active)
661 */
662function getActiveAndLazySources(
663 joinType: JoinClause[`type`],
664 leftCollection: Collection,
665 rightCollection: Collection,
666):
667 | { activeSource: `main` | `joined`; lazySource: Collection }
668 | { activeSource: undefined; lazySource: undefined } {
669 // Self-joins can now be optimized since we track lazy loading by source alias
670 // rather than collection ID. Each alias has its own subscription and lazy state.
671
672 switch (joinType) {
673 case `left`:
674 return { activeSource: `main`, lazySource: rightCollection }
675 case `right`:
676 return { activeSource: `joined`, lazySource: leftCollection }
677 case `inner`:
678 // The smallest collection should be the active collection
679 // and the biggest collection should be lazy
680 return leftCollection.size < rightCollection.size
681 ? { activeSource: `main`, lazySource: rightCollection }
682 : { activeSource: `joined`, lazySource: leftCollection }
683 default:
684 return { activeSource: undefined, lazySource: undefined }
685 }
686}

Callers 1

processJoinFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected