Skip unnecessary writes in default impl for modifyGet
This commit is contained in:
parent
b3d4bd40fc
commit
04fa15ca90
|
@ -71,6 +71,9 @@ method modifyGet*(self: Datastore, key: Key, fn: ModifyGet): Future[?!seq[byte]]
|
|||
## | some(u) | none | delete u |
|
||||
## | some(u) | some(v) | replace u with v (if u != v) |
|
||||
##
|
||||
## If `fn` raises an error, the value associated with `key` remains unchanged and raised error is wrapped
|
||||
## into a failure and returned as a result.
|
||||
##
|
||||
## Note that `fn` can be called multiple times (when concurrent modification was detected). In such case
|
||||
## only the last auxillary value is returned.
|
||||
##
|
||||
|
|
|
@ -37,6 +37,10 @@ proc defaultModifyGetImpl*(
|
|||
except CatchableError as err:
|
||||
return failure(err)
|
||||
|
||||
if maybeCurrentData == maybeNewData:
|
||||
# no need to change currently stored value (if any)
|
||||
return aux.success
|
||||
|
||||
if newData =? maybeNewData:
|
||||
if err =? (await self.put(key, newData)).errorOption:
|
||||
return failure(err)
|
||||
|
|
|
@ -66,7 +66,7 @@ method modifyGet*(self: SQLiteDatastore, key: Key, fn: ModifyGet): Future[?!seq[
|
|||
return failure(err)
|
||||
|
||||
if maybeCurrentData == maybeNewData:
|
||||
# no need to change currently stored value
|
||||
# no need to change currently stored value (if any)
|
||||
break
|
||||
|
||||
if err =? self.db.beginStmt.exec().errorOption:
|
||||
|
|
Loading…
Reference in New Issue