Commit 7095ffd
committed
fix(query-db-collection): prevent Direct Write items from being purged
Fixes issue where items inserted via Direct Writes (writeInsert/writeUpsert)
were incorrectly purged when query results changed and didn't include those items.
**Root Cause:**
The reference counting system (queryToRows/rowToQueries) tracks which items
are in each query result. When a query result doesn't include an item and the
item's reference count is 0, it gets deleted. Direct Write items were never
added to this tracking system, so they always had a reference count of 0 and
were purged when not in query results.
**Solution:**
- Added `directWriteKeys` Set to track items inserted via Direct Writes
- Modified purging logic in `handleQueryResult()` and `cleanupQuery()` to skip
items in the `directWriteKeys` Set
- Updated `performWriteOperations()` to add/remove keys from `directWriteKeys`:
- Insert operations add the key
- Delete operations remove the key
- Upsert operations add the key if inserting new item
**Changes:**
- query.ts: Added directWriteKeys Set and modified purging checks
- manual-sync.ts: Track direct write keys in performWriteOperations
- query.test.ts: Added test case to verify Direct Writes are protected
This ensures directly-written items persist until explicitly deleted via
writeDelete(), regardless of query result changes.1 parent 3e3504a commit 7095ffd
File tree
3 files changed
+105
-2
lines changed- packages/query-db-collection
- src
- tests
3 files changed
+105
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
| 152 | + | |
| 153 | + | |
151 | 154 | | |
152 | 155 | | |
153 | 156 | | |
| |||
175 | 178 | | |
176 | 179 | | |
177 | 180 | | |
| 181 | + | |
| 182 | + | |
178 | 183 | | |
179 | 184 | | |
180 | 185 | | |
| |||
195 | 200 | | |
196 | 201 | | |
197 | 202 | | |
| 203 | + | |
| 204 | + | |
198 | 205 | | |
199 | 206 | | |
200 | 207 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
592 | 592 | | |
593 | 593 | | |
594 | 594 | | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
595 | 599 | | |
596 | 600 | | |
597 | 601 | | |
| |||
780 | 784 | | |
781 | 785 | | |
782 | 786 | | |
783 | | - | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
784 | 790 | | |
785 | 791 | | |
786 | 792 | | |
| |||
932 | 938 | | |
933 | 939 | | |
934 | 940 | | |
935 | | - | |
| 941 | + | |
| 942 | + | |
936 | 943 | | |
937 | 944 | | |
938 | 945 | | |
| |||
957 | 964 | | |
958 | 965 | | |
959 | 966 | | |
| 967 | + | |
960 | 968 | | |
961 | 969 | | |
962 | 970 | | |
| |||
1024 | 1032 | | |
1025 | 1033 | | |
1026 | 1034 | | |
| 1035 | + | |
1027 | 1036 | | |
1028 | 1037 | | |
1029 | 1038 | | |
| |||
1039 | 1048 | | |
1040 | 1049 | | |
1041 | 1050 | | |
| 1051 | + | |
1042 | 1052 | | |
1043 | 1053 | | |
1044 | 1054 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3538 | 3538 | | |
3539 | 3539 | | |
3540 | 3540 | | |
| 3541 | + | |
| 3542 | + | |
| 3543 | + | |
| 3544 | + | |
| 3545 | + | |
| 3546 | + | |
| 3547 | + | |
| 3548 | + | |
| 3549 | + | |
| 3550 | + | |
| 3551 | + | |
| 3552 | + | |
| 3553 | + | |
| 3554 | + | |
| 3555 | + | |
| 3556 | + | |
| 3557 | + | |
| 3558 | + | |
| 3559 | + | |
| 3560 | + | |
| 3561 | + | |
| 3562 | + | |
| 3563 | + | |
| 3564 | + | |
| 3565 | + | |
| 3566 | + | |
| 3567 | + | |
| 3568 | + | |
| 3569 | + | |
| 3570 | + | |
| 3571 | + | |
| 3572 | + | |
| 3573 | + | |
| 3574 | + | |
| 3575 | + | |
| 3576 | + | |
| 3577 | + | |
| 3578 | + | |
| 3579 | + | |
| 3580 | + | |
| 3581 | + | |
| 3582 | + | |
| 3583 | + | |
| 3584 | + | |
| 3585 | + | |
| 3586 | + | |
| 3587 | + | |
| 3588 | + | |
| 3589 | + | |
| 3590 | + | |
| 3591 | + | |
| 3592 | + | |
| 3593 | + | |
| 3594 | + | |
| 3595 | + | |
| 3596 | + | |
| 3597 | + | |
| 3598 | + | |
| 3599 | + | |
| 3600 | + | |
| 3601 | + | |
| 3602 | + | |
| 3603 | + | |
| 3604 | + | |
| 3605 | + | |
| 3606 | + | |
| 3607 | + | |
| 3608 | + | |
| 3609 | + | |
| 3610 | + | |
| 3611 | + | |
| 3612 | + | |
| 3613 | + | |
| 3614 | + | |
| 3615 | + | |
| 3616 | + | |
| 3617 | + | |
| 3618 | + | |
| 3619 | + | |
| 3620 | + | |
| 3621 | + | |
| 3622 | + | |
| 3623 | + | |
| 3624 | + | |
| 3625 | + | |
| 3626 | + | |
3541 | 3627 | | |
0 commit comments