Skip to content

Commit

Permalink
Merge branch 'fix-candb-update-increment-bug' into 'beta'
Browse files Browse the repository at this point in the history
Fix for #28: No increment in CanDB.update during creation, resulting in...

See merge request origyn/engineering/opensource/candb-projects/CanDB!25
  • Loading branch information
ByronBecker committed Mar 20, 2024
2 parents d830b07 + ddce421 commit d767609
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/CanDB.mo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Iter "mo:base/Iter";
import Prim "mo:⛔";
import Text "mo:base/Text";

import { size } "mo:btree/BTree";

import E "Entity";
import RT "RangeTreeV2";

Expand Down Expand Up @@ -276,7 +278,14 @@ module {
public func update(db: DB, options: UpdateOptions): ?E.Entity {
let ovAttributeMap = RT.update(db.data, options.sk, options.updateAttributeMapFunction);
switch(ovAttributeMap) {
case null { null };
// entity did not previously exist, and was created
case null {
// Normally we would increment the count here, but due to the bug found in https://github.com/ORIGYN-SA/CanDB/issues/28
// This will apply a hot fix to the db count if it was off by more than 1
db.count := size(db.data);
null
};
// entity previously existed, return the original entity
case (?map) {
?{
pk = db.pk;
Expand Down

0 comments on commit d767609

Please sign in to comment.