chore: async filtering rows - #307
Merged
Merged
Conversation
Reviewer's GuideIntroduces async, seed-aware preloading for database rows to make sorting/filtering operate on progressively loaded row docs while keeping the UI responsive, wires blob diff seeds into background loading and ensureRow, and hides publish controls for database views in outline and breadcrumb components. Sequence diagram for async seed-aware row loading and ensureRow gatingsequenceDiagram
actor User
participant GridVirtualRow
participant useRowOrdersSelector
participant useBackgroundRowDocLoader
participant Database
participant prefetchDatabaseBlobDiff
participant IndexedDB
User->>GridVirtualRow: scrolls / opens database view
GridVirtualRow->>Database: ensureBlobPrefetch()
alt readOnly or missing workspaceId/databaseId
Database-->>Database: seedsGateRef.resolve()
Database-->>GridVirtualRow: return
else normal prefetch
Database->>prefetchDatabaseBlobDiff: prefetchDatabaseBlobDiff(workspaceId, databaseId, { priorityRowIds, onSeedsReady })
prefetchDatabaseBlobDiff-->>Database: cache seeds
prefetchDatabaseBlobDiff->>Database: options.onSeedsReady()
Database->>Database: runBatchPreload()
Database-->>Database: batchPreloadDoneRef = true
Database-->>Database: collect seeds for priorityRowIds
Database->>Database: createRowFast(rowKey, seed) for each row
Database-->>Database: setRowMap with preloaded rows
Database->>Database: requestAnimationFrame(registerRowSync)
Database-->>Database: seedsGateRef.resolve()
prefetchDatabaseBlobDiff->>IndexedDB: persist blobs and seeds
prefetchDatabaseBlobDiff-->>Database: promise resolved
Database-->>GridVirtualRow: blobPrefetchComplete = true
end
User->>GridVirtualRow: focuses or edits row
GridVirtualRow->>Database: ensureRow(rowId)
alt row already in rowMapRef
Database-->>Database: getDatabaseId, getRowKey
Database->>Database: registerRowSync(rowKey)
Database-->>GridVirtualRow: existing rowDoc
else row missing
Database->>Database: await seedsGateRef.promise
alt row added by batch preload
Database-->>Database: existingAfterGate in rowMapRef
Database->>Database: registerRowSync(rowKey)
Database-->>GridVirtualRow: existingAfterGate rowDoc
else still missing after gate
Database-->>Database: check pendingRowDocsRef
opt no pending
Database->>Database: createRow(rowKey)
Database-->>Database: pendingRowDocsRef.set(rowId, promise)
Database-->>Database: registerRowSync(rowKey)
end
Database-->>GridVirtualRow: awaited rowDoc
end
end
useRowOrdersSelector->>useBackgroundRowDocLoader: hasConditions = true
useBackgroundRowDocLoader-->>useBackgroundRowDocLoader: wait until blobPrefetchComplete
useBackgroundRowDocLoader->>Database: rows = useRowMap()
loop for each rowId in row_orders
alt rowDoc missing in rows and cachedRowDocsRef
useBackgroundRowDocLoader->>Database: populateRowFromCache(rowId)
alt seed exists
Database-->>useBackgroundRowDocLoader: promise<YDoc>
useBackgroundRowDocLoader-->>Database: await promise
Database-->>Database: rowMap updated via populateRowFromCache
useBackgroundRowDocLoader-->>useBackgroundRowDocLoader: doc found, skip IndexedDB
else no seed or failure
useBackgroundRowDocLoader->>IndexedDB: openCollabDBWithProvider(rowKey, { skipCache: true })
IndexedDB-->>useBackgroundRowDocLoader: doc
useBackgroundRowDocLoader-->>Database: provider.destroy()
useBackgroundRowDocLoader-->>useBackgroundRowDocLoader: cachedRowDocsRef updated
end
end
end
useBackgroundRowDocLoader-->>useRowOrdersSelector: updated rowDocsForConditions
useRowOrdersSelector-->>useRowOrdersSelector: recompute sorted/filtered rowOrders progressively
Class diagram for updated Database and background row loading hooksclassDiagram
class DatabaseComponent {
+workspaceId string
+doc YDoc
+readOnly boolean
+rowMap Record~string, YDoc~
+rowMapRef MutableRefObject~Record~string, YDoc~~
+prefetchPromisesRef MutableRefObject~Map~string, Promise~void~~
+blobPrefetchPromiseRef MutableRefObject~Promise~void~ or null~
+localCachePrimedRef MutableRefObject~boolean~
+syncedRowKeysRef MutableRefObject~Set~string~~
+batchPreloadDoneRef MutableRefObject~boolean~
+seedsGateRef MutableRefObject~DeferredGate~
+blobPrefetchComplete boolean
+ensureBlobPrefetch() Promise~void~ or null
+runBatchPreload() void
+ensureRow(rowId string) Promise~YDoc or void~
+resetOnDocChange() void
}
class DeferredGate {
+promise Promise~void~
+resolve() void
}
class PrefetchOptions {
+priorityRowIds string[]
+onSeedsReady() void
}
class DatabaseBlobModule {
+prefetchDatabaseBlobDiff(workspaceId string, databaseId string, options PrefetchOptions) Promise~void~
}
class UseBackgroundRowDocLoaderHook {
+hasConditions boolean
+cachedRowDocs Record~string, YDoc~
+cachedRowDocsRef MutableRefObject~Record~string, YDoc~~
+blobPrefetchComplete boolean
+populateRowFromCache(rowId string) Promise~YDoc or null~
+useBackgroundRowDocLoader(hasConditions boolean) RowDocLoaderResult
}
class RowDocLoaderResult {
+cachedRowDocs Record~string, YDoc~
+rowDocsForConditions Record~string, YDoc~
}
class UseRowOrdersSelectorHook {
+rowOrders Row[]
+originalRowOrders Row[]
+rowDocsForConditions Record~string, YDoc~
+filtersAppliedRef MutableRefObject~boolean~
+useRowOrdersSelector() RowOrdersResult
}
class RowOrdersResult {
+rowOrders Row[]
+rollupWatchVersion number
}
DatabaseComponent --> DeferredGate : uses via seedsGateRef
DatabaseComponent --> DatabaseBlobModule : calls prefetchDatabaseBlobDiff
DatabaseBlobModule --> PrefetchOptions : consumes
UseBackgroundRowDocLoaderHook --> DatabaseComponent : uses blobPrefetchComplete, populateRowFromCache
UseBackgroundRowDocLoaderHook --> RowDocLoaderResult : returns
UseRowOrdersSelectorHook --> UseBackgroundRowDocLoaderHook : uses rowDocsForConditions
UseRowOrdersSelectorHook --> RowOrdersResult : returns
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Checklist
General
Testing
Feature-Specific
Summary by Sourcery
Optimize database row loading and condition-based sorting/filtering by asynchronously preloading seeded row docs and progressively applying filters, while adjusting publish UI elements for database views.
New Features:
Enhancements: