Skip to content
Merged
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
6 changes: 3 additions & 3 deletions packages/common/src/client/AbstractPowerSyncDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
'SELECT priority, last_synced_at FROM ps_sync_state ORDER BY priority DESC'
);
let lastCompleteSync: Date | undefined;
const priorityStatuses: SyncPriorityStatus[] = [];
const priorityStatusEntries: SyncPriorityStatus[] = [];

for (const { priority, last_synced_at } of result) {
const parsedDate = new Date(last_synced_at + 'Z');
Expand All @@ -361,15 +361,15 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
// This lowest-possible priority represents a complete sync.
lastCompleteSync = parsedDate;
} else {
priorityStatuses.push({ priority, hasSynced: true, lastSyncedAt: parsedDate });
priorityStatusEntries.push({ priority, hasSynced: true, lastSyncedAt: parsedDate });
}
}

const hasSynced = lastCompleteSync != null;
const updatedStatus = new SyncStatus({
...this.currentStatus.toJSON(),
hasSynced,
priorityStatuses,
priorityStatusEntries,
lastSyncedAt: lastCompleteSync
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ The next upload iteration will be delayed.`);
this.logger.debug('partial checkpoint validation succeeded');

// All states with a higher priority can be deleted since this partial sync includes them.
const priorityStates = this.syncStatus.priorityStatuses.filter((s) => s.priority <= priority);
const priorityStates = this.syncStatus.priorityStatusEntries.filter((s) => s.priority <= priority);
priorityStates.push({
priority,
lastSyncedAt: new Date(),
Expand All @@ -619,7 +619,7 @@ The next upload iteration will be delayed.`);

this.updateSyncStatus({
connected: true,
priorityStatuses: priorityStates
priorityStatusEntries: priorityStates
});
}
} else if (isStreamingSyncCheckpointDiff(line)) {
Expand Down Expand Up @@ -688,7 +688,7 @@ The next upload iteration will be delayed.`);
this.updateSyncStatus({
connected: true,
lastSyncedAt: new Date(),
priorityStatuses: []
priorityStatusEntries: []
});
} else if (validatedCheckpoint === targetCheckpoint) {
const result = await this.options.adapter.syncLocalDatabase(targetCheckpoint!);
Expand All @@ -705,7 +705,7 @@ The next upload iteration will be delayed.`);
this.updateSyncStatus({
connected: true,
lastSyncedAt: new Date(),
priorityStatuses: [],
priorityStatusEntries: [],
dataFlow: {
downloading: false
}
Expand All @@ -730,7 +730,7 @@ The next upload iteration will be delayed.`);
...this.syncStatus.dataFlowStatus,
...options.dataFlow
},
priorityStatuses: options.priorityStatuses ?? this.syncStatus.priorityStatuses
priorityStatusEntries: options.priorityStatusEntries ?? this.syncStatus.priorityStatusEntries
});

if (!this.syncStatus.isEqual(updatedStatus)) {
Expand Down
12 changes: 6 additions & 6 deletions packages/common/src/db/crud/SyncStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type SyncStatusOptions = {
dataFlow?: SyncDataFlowStatus;
lastSyncedAt?: Date;
hasSynced?: boolean;
priorityStatuses?: SyncPriorityStatus[];
priorityStatusEntries?: SyncPriorityStatus[];
};

export class SyncStatus {
Expand Down Expand Up @@ -70,8 +70,8 @@ export class SyncStatus {
/**
* Partial sync status for involved bucket priorities.
*/
get priorityStatuses() {
return (this.options.priorityStatuses ?? []).toSorted(SyncStatus.comparePriorities);
get priorityStatusEntries() {
return (this.options.priorityStatusEntries ?? []).toSorted(SyncStatus.comparePriorities);
}

/**
Expand All @@ -90,8 +90,8 @@ export class SyncStatus {
* @param priority The bucket priority for which the status should be reported.
*/
statusForPriority(priority: number): SyncPriorityStatus {
// priorityStatuses are sorted by ascending priorities (so higher numbers to lower numbers).
for (const known of this.priorityStatuses) {
// priorityStatusEntries are sorted by ascending priorities (so higher numbers to lower numbers).
for (const known of this.priorityStatusEntries) {
// We look for the first entry that doesn't have a higher priority.
if (known.priority >= priority) {
return known;
Expand Down Expand Up @@ -122,7 +122,7 @@ export class SyncStatus {
dataFlow: this.dataFlowStatus,
lastSyncedAt: this.lastSyncedAt,
hasSynced: this.hasSynced,
priorityStatuses: this.priorityStatuses
priorityStatusEntries: this.priorityStatusEntries
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/web/tests/stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe(
});
await another.init();

expect(another.currentStatus.priorityStatuses).toHaveLength(1);
expect(another.currentStatus.priorityStatusEntries).toHaveLength(1);
expect(another.currentStatus.statusForPriority(0).hasSynced).toBeTruthy();
await another.waitForFirstSync({ priority: 0 });
});
Expand Down