Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
647 changes: 0 additions & 647 deletions AGENTS.md

This file was deleted.

38 changes: 6 additions & 32 deletions packages/db/src/collection/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { BasicExpression, OrderBy } from "../query/ir.js"
import type { IndexInterface } from "../indexes/base-index.js"
import type {
ChangeMessage,
LoadSubsetOptions,
Subscription,
SubscriptionEvents,
SubscriptionStatus,
Expand Down Expand Up @@ -48,12 +47,6 @@ export class CollectionSubscription
// While `snapshotSent` is false we filter out all changes from subscription to the collection.
private snapshotSent = false

/**
* Track all loadSubset calls made by this subscription so we can unload them on cleanup.
* We store the exact LoadSubsetOptions we passed to loadSubset to ensure symmetric unload.
*/
private loadedSubsets: Array<LoadSubsetOptions> = []

// Keep track of the keys we've sent (needed for join and orderBy optimizations)
private sentKeys = new Set<string | number>()

Expand Down Expand Up @@ -200,14 +193,10 @@ export class CollectionSubscription

// Request the sync layer to load more data
// don't await it, we will load the data into the collection when it comes in
const loadOptions: LoadSubsetOptions = {
const syncResult = this.collection._sync.loadSubset({
where: stateOpts.where,
subscription: this,
}
const syncResult = this.collection._sync.loadSubset(loadOptions)

// Track this loadSubset call so we can unload it later
this.loadedSubsets.push(loadOptions)
})

const trackLoadSubsetPromise = opts?.trackLoadSubsetPromise ?? true
if (trackLoadSubsetPromise) {
Expand Down Expand Up @@ -344,16 +333,12 @@ export class CollectionSubscription

// Request the sync layer to load more data
// don't await it, we will load the data into the collection when it comes in
const loadOptions1: LoadSubsetOptions = {
const syncResult = this.collection._sync.loadSubset({
where: whereWithValueFilter,
limit,
orderBy,
subscription: this,
}
const syncResult = this.collection._sync.loadSubset(loadOptions1)

// Track this loadSubset call
this.loadedSubsets.push(loadOptions1)
})

// Make parallel loadSubset calls for values equal to minValue and values greater than minValue
const promises: Array<Promise<void>> = []
Expand All @@ -363,14 +348,10 @@ export class CollectionSubscription
const { expression } = orderBy[0]!
const exactValueFilter = eq(expression, new Value(minValue))

const loadOptions2: LoadSubsetOptions = {
const equalValueResult = this.collection._sync.loadSubset({
where: exactValueFilter,
subscription: this,
}
const equalValueResult = this.collection._sync.loadSubset(loadOptions2)

// Track this loadSubset call
this.loadedSubsets.push(loadOptions2)
})

if (equalValueResult instanceof Promise) {
promises.push(equalValueResult)
Expand Down Expand Up @@ -436,13 +417,6 @@ export class CollectionSubscription
}

unsubscribe() {
// Unload all subsets that this subscription loaded
// We pass the exact same LoadSubsetOptions we used for loadSubset
for (const options of this.loadedSubsets) {
this.collection._sync.unloadSubset(options)
}
this.loadedSubsets = []

this.emitInner(`unsubscribed`, {
type: `unsubscribed`,
subscription: this,
Expand Down
15 changes: 0 additions & 15 deletions packages/db/src/collection/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export class CollectionSyncManager<
public syncLoadSubsetFn:
| ((options: LoadSubsetOptions) => true | Promise<void>)
| null = null
public syncUnloadSubsetFn: ((options: LoadSubsetOptions) => void) | null =
null

private pendingLoadSubsetPromises: Set<Promise<void>> = new Set()

Expand Down Expand Up @@ -211,9 +209,6 @@ export class CollectionSyncManager<
// Store loadSubset function if provided
this.syncLoadSubsetFn = syncRes?.loadSubset ?? null

// Store unloadSubset function if provided
this.syncUnloadSubsetFn = syncRes?.unloadSubset ?? null

// Validate: on-demand mode requires a loadSubset function
if (this.syncMode === `on-demand` && !this.syncLoadSubsetFn) {
throw new CollectionConfigurationError(
Expand Down Expand Up @@ -346,16 +341,6 @@ export class CollectionSyncManager<
return true
}

/**
* Notifies the sync layer that a subset is no longer needed.
* @param options Options that identify what data is being unloaded
*/
public unloadSubset(options: LoadSubsetOptions): void {
if (this.syncUnloadSubsetFn) {
this.syncUnloadSubsetFn(options)
}
}

public cleanup(): void {
try {
if (this.syncCleanupFn) {
Expand Down
3 changes: 0 additions & 3 deletions packages/db/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,11 @@ export type LoadSubsetOptions = {

export type LoadSubsetFn = (options: LoadSubsetOptions) => true | Promise<void>

export type UnloadSubsetFn = (options: LoadSubsetOptions) => void

export type CleanupFn = () => void

export type SyncConfigRes = {
cleanup?: CleanupFn
loadSubset?: LoadSubsetFn
unloadSubset?: UnloadSubsetFn
}
export interface SyncConfig<
T extends object = Record<string, unknown>,
Expand Down
9 changes: 0 additions & 9 deletions packages/query-db-collection/e2e/query.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,24 @@ describe(`Query Collection E2E Tests`, () => {
// Mutations for Query collections - modify seed data and invalidate queries
mutations: {
insertUser: async (user) => {
console.log(`[mutation] insertUser called, id=${user.id}`)
seedData.users.push(user)
console.log(`[mutation] calling invalidateQueries`)
await queryClient.invalidateQueries({ queryKey: [`e2e`, `users`] })
console.log(`[mutation] invalidateQueries completed`)
},
updateUser: async (id, updates) => {
console.log(`[mutation] updateUser called, id=${id}`)
const userIndex = seedData.users.findIndex((u) => u.id === id)
if (userIndex !== -1) {
seedData.users[userIndex] = {
...seedData.users[userIndex]!,
...updates,
}
console.log(`[mutation] calling invalidateQueries`)
await queryClient.invalidateQueries({ queryKey: [`e2e`, `users`] })
console.log(`[mutation] invalidateQueries completed`)
}
},
deleteUser: async (id) => {
console.log(`[mutation] deleteUser called, id=${id}`)
const userIndex = seedData.users.findIndex((u) => u.id === id)
if (userIndex !== -1) {
seedData.users.splice(userIndex, 1)
console.log(`[mutation] calling invalidateQueries`)
await queryClient.invalidateQueries({ queryKey: [`e2e`, `users`] })
console.log(`[mutation] invalidateQueries completed`)
}
},
insertPost: async (post) => {
Expand Down
Loading
Loading