Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
client
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
client
Commits
ce863399
Commit
ce863399
authored
Aug 10, 2020
by
Niamh Nikali
Browse files
Options
Downloads
Patches
Plain Diff
Add memoization, remove user ID key
parent
aed2fce2
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
storage/session.go
+3
-2
3 additions, 2 deletions
storage/session.go
storage/userdata.go
+13
-5
13 additions, 5 deletions
storage/userdata.go
storage/userdata_test.go
+3
-3
3 additions, 3 deletions
storage/userdata_test.go
with
19 additions
and
10 deletions
storage/session.go
+
3
−
2
View file @
ce863399
...
...
@@ -24,6 +24,7 @@ import (
// Session object, backed by encrypted filestore
type
Session
struct
{
kv
*
VersionedKV
userData
*
UserData
mux
sync
.
Mutex
}
...
...
...
...
This diff is collapsed.
Click to expand it.
storage/userdata.go
+
13
−
5
View file @
ce863399
...
...
@@ -51,12 +51,16 @@ type UserData struct {
const
currentUserDataVersion
=
0
func
makeUserDataKey
(
userID
*
id
.
ID
)
string
{
return
MakeKeyPrefix
(
"UserData"
,
currentUserDataVersion
)
+
userID
.
String
()
func
makeUserDataKey
()
string
{
return
MakeKeyPrefix
(
"UserData"
,
currentUserDataVersion
)
}
func
(
s
*
Session
)
GetUserData
(
userID
*
id
.
ID
)
(
*
UserData
,
error
)
{
obj
,
err
:=
s
.
Get
(
makeUserDataKey
(
userID
))
func
(
s
*
Session
)
GetUserData
()
(
*
UserData
,
error
)
{
if
s
.
userData
!=
nil
{
// We already got this and don't need to get it again
return
s
.
userData
,
nil
}
obj
,
err
:=
s
.
Get
(
makeUserDataKey
())
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -69,11 +73,15 @@ func (s *Session) GetUserData(userID *id.ID) (*UserData, error) {
if
err
!=
nil
{
return
nil
,
err
}
s
.
userData
=
&
result
return
&
result
,
nil
}
// Make changes to the user data after getting it, then
// commit those changes to the ekv store using this
// I haven't added a mutex to the user data because it's only
// created once. If you add modification to the user data structure,
// please
func
(
s
*
Session
)
CommitUserData
(
data
*
UserData
)
error
{
// Serialize the data
var
userDataBuffer
bytes
.
Buffer
...
...
@@ -88,5 +96,5 @@ func (s *Session) CommitUserData(data *UserData) error {
Timestamp
:
time
.
Now
(),
Data
:
userDataBuffer
.
Bytes
(),
}
return
s
.
Set
(
makeUserDataKey
(
data
.
ThisUser
.
User
),
obj
)
return
s
.
Set
(
makeUserDataKey
(),
obj
)
}
This diff is collapsed.
Click to expand it.
storage/userdata_test.go
+
3
−
3
View file @
ce863399
...
...
@@ -46,7 +46,7 @@ func TestSession_CommitUserData(t *testing.T) {
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
retrievedData
,
err
:=
session
.
GetUserData
(
expectedData
.
ThisUser
.
User
)
retrievedData
,
err
:=
session
.
GetUserData
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -79,8 +79,8 @@ func TestSession_CommitUserData(t *testing.T) {
if
!
reflect
.
DeepEqual
(
retrievedData
.
E2EGrp
,
expectedData
.
E2EGrp
)
{
t
.
Error
(
"e2e groups didn't match"
)
}
if
!
reflect
.
DeepEqual
(
retrievedData
.
RSAPrivateKey
,
expectedData
.
RSAPrivateKey
)
{
t
.
Error
(
"rsa
keys
don't match"
)
if
retrievedData
.
RSAPrivateKey
.
D
.
Cmp
(
expectedData
.
RSAPrivateKey
.
D
)
!=
0
{
t
.
Error
(
"rsa
D
do
es
n't match"
)
}
if
!
bytes
.
Equal
(
retrievedData
.
Salt
,
expectedData
.
Salt
)
{
t
.
Error
(
"salts don't match"
)
...
...
...
...
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
sign in
to comment