(opts: LoadSubsetOptions)
| 441 | } |
| 442 | |
| 443 | const loadSubset = async (opts: LoadSubsetOptions) => { |
| 444 | if (isBufferingInitialSync()) { |
| 445 | const snapshotParams = compileSQL<T>(opts, compileOptions) |
| 446 | try { |
| 447 | const { data: rows } = await stream.fetchSnapshot(snapshotParams) |
| 448 | |
| 449 | if (!isBufferingInitialSync()) { |
| 450 | debug(`${logPrefix}Ignoring snapshot - sync completed while fetching`) |
| 451 | return |
| 452 | } |
| 453 | |
| 454 | if (rows.length > 0) { |
| 455 | begin() |
| 456 | for (const row of rows) { |
| 457 | write({ |
| 458 | type: `insert`, |
| 459 | value: row.value, |
| 460 | metadata: { ...row.headers }, |
| 461 | }) |
| 462 | } |
| 463 | commit() |
| 464 | debug(`${logPrefix}Applied snapshot with ${rows.length} rows`) |
| 465 | } |
| 466 | } catch (error) { |
| 467 | if (handleSnapshotError(error, `fetchSnapshot`)) { |
| 468 | return |
| 469 | } |
| 470 | throw error |
| 471 | } |
| 472 | return |
| 473 | } |
| 474 | |
| 475 | if (syncMode === `progressive`) { |
| 476 | return |
| 477 | } |
| 478 | |
| 479 | const { cursor, where, orderBy, limit } = opts |
| 480 | |
| 481 | // When the stream is already up-to-date, it may be in a long-poll wait. |
| 482 | // Forcing a disconnect-and-refresh ensures requestSnapshot gets a response |
| 483 | // from a fresh server round-trip rather than waiting for the current poll to end. |
| 484 | // If the refresh fails (e.g., PauseLock held during subscriber processing in |
| 485 | // join pipelines), we fall through to requestSnapshot which still works. |
| 486 | if (stream.isUpToDate) { |
| 487 | try { |
| 488 | await stream.forceDisconnectAndRefresh() |
| 489 | } catch (error) { |
| 490 | if (handleSnapshotError(error, `forceDisconnectAndRefresh`)) { |
| 491 | return |
| 492 | } |
| 493 | debug( |
| 494 | `${logPrefix}forceDisconnectAndRefresh failed, proceeding to requestSnapshot: %o`, |
| 495 | error, |
| 496 | ) |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | try { |
nothing calls this directly
no test coverage detected