Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xxdk-wasm
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
xxdk-wasm
Commits
1a89f853
Commit
1a89f853
authored
2 years ago
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
simplify put function
parent
227cdd76
No related branches found
No related tags found
Loading
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
indexedDb/channels/implementation.go
+3
-7
3 additions, 7 deletions
indexedDb/channels/implementation.go
indexedDb/dm/implementation.go
+3
-7
3 additions, 7 deletions
indexedDb/dm/implementation.go
indexedDb/utils.go
+7
-7
7 additions, 7 deletions
indexedDb/utils.go
with
13 additions
and
21 deletions
indexedDb/channels/implementation.go
+
3
−
7
View file @
1a89f853
...
...
@@ -377,18 +377,14 @@ func (w *wasmModel) receiveHelper(newMessage *Message, isUpdate bool) (uint64,
}
// Store message to database
addReq
,
err
:=
indexedDb
.
Put
(
w
.
db
,
messageStoreName
,
messageObj
)
result
,
err
:=
indexedDb
.
Put
(
w
.
db
,
messageStoreName
,
messageObj
)
if
err
!=
nil
{
return
0
,
errors
.
Errorf
(
"Unable to put Message: %+v"
,
err
)
}
res
,
err
:=
addReq
.
Result
()
if
err
!=
nil
{
return
0
,
errors
.
Errorf
(
"Unable to get Message result: %+v"
,
err
)
}
// NOTE: Sometimes the insert fails to return an error but hits a duplicate
// insert, so this fallthrough returns the UUID entry in that case.
if
res
.
IsUndefined
()
{
if
res
ult
.
IsUndefined
()
{
msgID
:=
message
.
ID
{}
copy
(
msgID
[
:
],
newMessage
.
MessageID
)
uuid
,
errLookup
:=
w
.
msgIDLookup
(
msgID
)
...
...
@@ -397,7 +393,7 @@ func (w *wasmModel) receiveHelper(newMessage *Message, isUpdate bool) (uint64,
}
return
0
,
errors
.
Errorf
(
"uuid lookup failure: %+v"
,
err
)
}
uuid
:=
uint64
(
res
.
Int
())
uuid
:=
uint64
(
res
ult
.
Int
())
jww
.
DEBUG
.
Printf
(
"Successfully stored message %d"
,
uuid
)
return
uuid
,
nil
...
...
This diff is collapsed.
Click to expand it.
indexedDb/dm/implementation.go
+
3
−
7
View file @
1a89f853
...
...
@@ -341,18 +341,14 @@ func (w *wasmModel) receiveHelper(newMessage *Message, isUpdate bool) (uint64,
}
// Store message to database
addReq
,
err
:=
indexedDb
.
Put
(
w
.
db
,
messageStoreName
,
messageObj
)
result
,
err
:=
indexedDb
.
Put
(
w
.
db
,
messageStoreName
,
messageObj
)
if
err
!=
nil
{
return
0
,
errors
.
Errorf
(
"Unable to put Message: %+v"
,
err
)
}
res
,
err
:=
addReq
.
Result
()
if
err
!=
nil
{
return
0
,
errors
.
Errorf
(
"Unable to get Message result: %+v"
,
err
)
}
// NOTE: Sometimes the insert fails to return an error but hits a duplicate
// insert, so this fallthrough returns the UUID entry in that case.
if
res
.
IsUndefined
()
{
if
res
ult
.
IsUndefined
()
{
msgID
:=
message
.
ID
{}
copy
(
msgID
[
:
],
newMessage
.
MessageID
)
uuid
,
errLookup
:=
w
.
msgIDLookup
(
msgID
)
...
...
@@ -361,7 +357,7 @@ func (w *wasmModel) receiveHelper(newMessage *Message, isUpdate bool) (uint64,
}
return
0
,
errors
.
Errorf
(
"uuid lookup failure: %+v"
,
err
)
}
uuid
:=
uint64
(
res
.
Int
())
uuid
:=
uint64
(
res
ult
.
Int
())
jww
.
DEBUG
.
Printf
(
"Successfully stored message %d"
,
uuid
)
return
uuid
,
nil
...
...
This diff is collapsed.
Click to expand it.
indexedDb/utils.go
+
7
−
7
View file @
1a89f853
...
...
@@ -127,33 +127,33 @@ func GetIndex(db *idb.Database, objectStoreName string,
// Put is a generic helper for putting values into the given [idb.ObjectStore].
// Equivalent to insert if not exists else update.
func
Put
(
db
*
idb
.
Database
,
objectStoreName
string
,
value
js
.
Value
)
(
*
idb
.
Request
,
error
)
{
func
Put
(
db
*
idb
.
Database
,
objectStoreName
string
,
value
js
.
Value
)
(
js
.
Value
,
error
)
{
// Prepare the Transaction
txn
,
err
:=
db
.
Transaction
(
idb
.
TransactionReadWrite
,
objectStoreName
)
if
err
!=
nil
{
return
nil
,
errors
.
Errorf
(
"Unable to create Transaction: %+v"
,
err
)
return
js
.
Undefined
()
,
errors
.
Errorf
(
"Unable to create Transaction: %+v"
,
err
)
}
store
,
err
:=
txn
.
ObjectStore
(
objectStoreName
)
if
err
!=
nil
{
return
nil
,
errors
.
Errorf
(
"Unable to get ObjectStore: %+v"
,
err
)
return
js
.
Undefined
()
,
errors
.
Errorf
(
"Unable to get ObjectStore: %+v"
,
err
)
}
// Perform the operation
request
,
err
:=
store
.
Put
(
value
)
if
err
!=
nil
{
return
nil
,
errors
.
Errorf
(
"Unable to Put: %+v"
,
err
)
return
js
.
Undefined
()
,
errors
.
Errorf
(
"Unable to Put: %+v"
,
err
)
}
// Wait for the operation to return
ctx
,
cancel
:=
NewContext
()
err
=
txn
.
Await
(
ctx
)
result
,
err
:
=
request
.
Await
(
ctx
)
cancel
()
if
err
!=
nil
{
return
nil
,
errors
.
Errorf
(
"Putting value failed: %+v"
,
err
)
return
js
.
Undefined
()
,
errors
.
Errorf
(
"Putting value failed: %+v"
,
err
)
}
jww
.
DEBUG
.
Printf
(
"Successfully put value in %s: %v"
,
objectStoreName
,
utils
.
JsToJson
(
value
))
return
re
ques
t
,
nil
return
re
sul
t
,
nil
}
// Delete is a generic helper for removing values from the given [idb.ObjectStore].
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment