-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
39 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { reversed } from "../../../../util/util"; | ||
import { KVData, VersionedValue } from "./types"; | ||
|
||
export function getVisibleValue( | ||
isTxnCommitted: (txnID: string) => boolean, | ||
kvData: KVData, | ||
key: string | ||
): VersionedValue | null { | ||
if (!kvData[key]) { | ||
return null; | ||
} | ||
|
||
for (const vv of reversed(kvData[key])) { | ||
if (isTxnCommitted(vv.transactionID)) { | ||
return vv; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
export function addNewVersion( | ||
kvData: KVData, | ||
key: string, | ||
newVersion: VersionedValue | ||
) { | ||
const versions = kvData[key] || []; | ||
// Check if the transactionID is already in the list | ||
// This can result from overlapping live queries | ||
// TODO: this is O(n) and could be O(1) | ||
if (versions.some((v) => v.transactionID === newVersion.transactionID)) { | ||
return versions; | ||
} | ||
return [...versions, newVersion]; | ||
} |
This file contains 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
This file contains 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