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
f2b32423
Commit
f2b32423
authored
2 years ago
by
Jono Wenger
Browse files
Options
Downloads
Plain Diff
Merge branch 'XX-4448/purgeBug' into 'release'
Xx 4448/purge bug See merge request
!64
parents
fea2826e
b0e6dae2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!67
fix for latest client release
,
!64
Xx 4448/purge bug
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
storage/localStorage.go
+14
-4
14 additions, 4 deletions
storage/localStorage.go
storage/localStorage_test.go
+15
-4
15 additions, 4 deletions
storage/localStorage_test.go
storage/purge.go
+16
-8
16 additions, 8 deletions
storage/purge.go
with
45 additions
and
16 deletions
storage/localStorage.go
+
14
−
4
View file @
f2b32423
...
...
@@ -114,36 +114,46 @@ func (ls *LocalStorage) Clear() {
ls
.
clear
()
}
// ClearPrefix clears all keys with the given prefix.
func
(
ls
*
LocalStorage
)
ClearPrefix
(
prefix
string
)
{
// ClearPrefix clears all keys with the given prefix. Returns the number of
// keys cleared.
func
(
ls
*
LocalStorage
)
ClearPrefix
(
prefix
string
)
int
{
// Get a copy of all key names at once
keys
:=
ls
.
keys
()
// Loop through each key
var
n
int
for
i
:=
0
;
i
<
keys
.
Length
();
i
++
{
if
v
:=
keys
.
Index
(
i
);
!
v
.
IsNull
()
{
keyName
:=
strings
.
TrimPrefix
(
v
.
String
(),
ls
.
prefix
)
if
strings
.
HasPrefix
(
keyName
,
prefix
)
{
ls
.
removeItem
(
v
.
String
())
n
++
}
}
}
return
n
}
// ClearWASM clears all the keys in storage created by WASM.
func
(
ls
*
LocalStorage
)
ClearWASM
()
{
// ClearWASM clears all the keys in storage created by WASM. Returns the number
// of keys cleared.
func
(
ls
*
LocalStorage
)
ClearWASM
()
int
{
// Get a copy of all key names at once
keys
:=
ls
.
keys
()
// Loop through each key
var
n
int
for
i
:=
0
;
i
<
keys
.
Length
();
i
++
{
if
v
:=
keys
.
Index
(
i
);
!
v
.
IsNull
()
{
keyName
:=
v
.
String
()
if
strings
.
HasPrefix
(
keyName
,
ls
.
prefix
)
{
ls
.
RemoveItem
(
strings
.
TrimPrefix
(
keyName
,
ls
.
prefix
))
n
++
}
}
}
return
n
}
// Key returns the name of the nth key in localStorage. Return os.ErrNotExist if
...
...
This diff is collapsed.
Click to expand it.
storage/localStorage_test.go
+
15
−
4
View file @
f2b32423
...
...
@@ -91,10 +91,11 @@ func TestLocalStorage_ClearPrefix(t *testing.T) {
s
:=
newLocalStorage
(
""
)
s
.
clear
()
prng
:=
rand
.
New
(
rand
.
NewSource
(
11
))
const
numKeys
=
10
var
yesPrefix
,
noPrefix
[]
string
prefix
:=
"keyNamePrefix/"
for
i
:=
0
;
i
<
10
;
i
++
{
for
i
:=
0
;
i
<
numKeys
;
i
++
{
keyName
:=
"keyNum"
+
strconv
.
Itoa
(
i
)
if
prng
.
Intn
(
2
)
==
0
{
keyName
=
prefix
+
keyName
...
...
@@ -106,7 +107,11 @@ func TestLocalStorage_ClearPrefix(t *testing.T) {
s
.
SetItem
(
keyName
,
[]
byte
(
strconv
.
Itoa
(
i
)))
}
s
.
ClearPrefix
(
prefix
)
n
:=
s
.
ClearPrefix
(
prefix
)
if
n
!=
numKeys
/
2
{
t
.
Errorf
(
"Incorrect number of keys.
\n
expected: %d
\n
received: %d"
,
numKeys
/
2
,
n
)
}
for
_
,
keyName
:=
range
noPrefix
{
if
_
,
err
:=
s
.
GetItem
(
keyName
);
err
!=
nil
{
...
...
@@ -126,8 +131,10 @@ func TestLocalStorage_ClearPrefix(t *testing.T) {
func
TestLocalStorage_ClearWASM
(
t
*
testing
.
T
)
{
jsStorage
.
clear
()
prng
:=
rand
.
New
(
rand
.
NewSource
(
11
))
const
numKeys
=
10
var
yesPrefix
,
noPrefix
[]
string
for
i
:=
0
;
i
<
10
;
i
++
{
for
i
:=
0
;
i
<
numKeys
;
i
++
{
keyName
:=
"keyNum"
+
strconv
.
Itoa
(
i
)
if
prng
.
Intn
(
2
)
==
0
{
yesPrefix
=
append
(
yesPrefix
,
keyName
)
...
...
@@ -138,7 +145,11 @@ func TestLocalStorage_ClearWASM(t *testing.T) {
}
}
jsStorage
.
ClearWASM
()
n
:=
jsStorage
.
ClearWASM
()
if
n
!=
numKeys
/
2
{
t
.
Errorf
(
"Incorrect number of keys.
\n
expected: %d
\n
received: %d"
,
numKeys
/
2
,
n
)
}
for
_
,
keyName
:=
range
noPrefix
{
if
v
:=
jsStorage
.
getItem
(
keyName
);
v
.
IsNull
()
{
...
...
This diff is collapsed.
Click to expand it.
storage/purge.go
+
16
−
8
View file @
f2b32423
...
...
@@ -12,6 +12,7 @@ package storage
import
(
"github.com/hack-pad/go-indexeddb/idb"
"github.com/pkg/errors"
jww
"github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/v4/storage/utility"
"gitlab.com/elixxir/xxdk-wasm/utils"
"sync/atomic"
...
...
@@ -61,11 +62,11 @@ func Purge(_ js.Value, args []js.Value) any {
}
// Verify all Cmix followers are stopped
//
if n := atomic.LoadUint64(&numClientsRunning); n != 0 {
//
utils.Throw(utils.TypeError, errors.Errorf(
//
"%d cMix followers running; all need to be stopped", n))
//
return nil
//
}
if
n
:=
atomic
.
LoadUint64
(
&
numClientsRunning
);
n
!=
0
{
utils
.
Throw
(
utils
.
TypeError
,
errors
.
Errorf
(
"%d cMix followers running; all need to be stopped"
,
n
))
return
nil
}
// Get all indexedDb database names
databaseList
,
err
:=
GetIndexedDbList
()
...
...
@@ -74,6 +75,8 @@ func Purge(_ js.Value, args []js.Value) any {
"failed to get list of indexedDb database names: %+v"
,
err
))
return
nil
}
jww
.
DEBUG
.
Printf
(
"[PURGE] Found %d databases to delete: %s"
,
len
(
databaseList
),
databaseList
)
// Delete each database
for
dbName
:=
range
databaseList
{
...
...
@@ -89,13 +92,18 @@ func Purge(_ js.Value, args []js.Value) any {
ls
:=
GetLocalStorage
()
// Clear all local storage saved by this WASM project
ls
.
ClearWASM
()
n
:=
ls
.
ClearWASM
()
jww
.
DEBUG
.
Printf
(
"[PURGE] Cleared %d WASM keys in local storage"
,
n
)
// Clear all EKV from local storage
ls
.
ClearPrefix
(
storageDirectory
)
n
=
ls
.
ClearPrefix
(
storageDirectory
)
jww
.
DEBUG
.
Printf
(
"[PURGE] Cleared %d keys with the prefix %q (for EKV)"
,
n
,
storageDirectory
)
// Clear all NDFs saved to local storage
ls
.
ClearPrefix
(
utility
.
NdfStorageKeyNamePrefix
)
n
=
ls
.
ClearPrefix
(
utility
.
NdfStorageKeyNamePrefix
)
jww
.
DEBUG
.
Printf
(
"[PURGE] Cleared %d keys with the prefix %q (for NDF)"
,
n
,
utility
.
NdfStorageKeyNamePrefix
)
return
nil
}
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