Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-datastore
Commits
0ab21bf7
Commit
0ab21bf7
authored
Mar 20, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mount: add filter support
parent
42a00bc0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
9 deletions
+17
-9
mount/mount.go
mount/mount.go
+17
-9
No files found.
mount/mount.go
View file @
0ab21bf7
...
@@ -80,7 +80,7 @@ func (qr *queryResults) advance() bool {
...
@@ -80,7 +80,7 @@ func (qr *queryResults) advance() bool {
}
}
type
querySet
struct
{
type
querySet
struct
{
order
[]
query
.
Ord
er
query
query
.
Qu
er
y
heads
[]
*
queryResults
heads
[]
*
queryResults
}
}
...
@@ -89,7 +89,7 @@ func (h *querySet) Len() int {
...
@@ -89,7 +89,7 @@ func (h *querySet) Len() int {
}
}
func
(
h
*
querySet
)
Less
(
i
,
j
int
)
bool
{
func
(
h
*
querySet
)
Less
(
i
,
j
int
)
bool
{
return
query
.
Less
(
h
.
o
rder
,
h
.
heads
[
i
]
.
next
.
Entry
,
h
.
heads
[
j
]
.
next
.
Entry
)
return
query
.
Less
(
h
.
query
.
O
rder
s
,
h
.
heads
[
i
]
.
next
.
Entry
,
h
.
heads
[
j
]
.
next
.
Entry
)
}
}
func
(
h
*
querySet
)
Swap
(
i
,
j
int
)
{
func
(
h
*
querySet
)
Swap
(
i
,
j
int
)
{
...
@@ -137,12 +137,20 @@ func (h *querySet) next() (query.Result, bool) {
...
@@ -137,12 +137,20 @@ func (h *querySet) next() (query.Result, bool) {
if
len
(
h
.
heads
)
==
0
{
if
len
(
h
.
heads
)
==
0
{
return
query
.
Result
{},
false
return
query
.
Result
{},
false
}
}
next
:=
h
.
heads
[
0
]
.
next
head
:=
h
.
heads
[
0
]
if
h
.
heads
[
0
]
.
advance
()
{
next
:=
head
.
next
for
head
.
advance
()
{
if
head
.
next
.
Error
==
nil
{
for
_
,
f
:=
range
h
.
query
.
Filters
{
if
!
f
.
Filter
(
head
.
next
.
Entry
)
{
continue
}
}
}
heap
.
Fix
(
h
,
0
)
heap
.
Fix
(
h
,
0
)
}
else
{
return
next
,
true
heap
.
Remove
(
h
,
0
)
}
}
heap
.
Remove
(
h
,
0
)
return
next
,
true
return
next
,
true
}
}
...
@@ -219,8 +227,7 @@ func (d *Datastore) Delete(key ds.Key) error {
...
@@ -219,8 +227,7 @@ func (d *Datastore) Delete(key ds.Key) error {
}
}
func
(
d
*
Datastore
)
Query
(
q
query
.
Query
)
(
query
.
Results
,
error
)
{
func
(
d
*
Datastore
)
Query
(
q
query
.
Query
)
(
query
.
Results
,
error
)
{
if
len
(
q
.
Filters
)
>
0
||
if
q
.
Limit
>
0
||
q
.
Limit
>
0
||
q
.
Offset
>
0
{
q
.
Offset
>
0
{
// TODO this is still overly simplistic, but the only callers are
// TODO this is still overly simplistic, but the only callers are
// `ipfs refs local` and ipfs-ds-convert.
// `ipfs refs local` and ipfs-ds-convert.
...
@@ -230,7 +237,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
...
@@ -230,7 +237,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
dses
,
mounts
,
rests
:=
d
.
lookupAll
(
prefix
)
dses
,
mounts
,
rests
:=
d
.
lookupAll
(
prefix
)
queries
:=
&
querySet
{
queries
:=
&
querySet
{
ord
er
:
q
.
Orders
,
qu
er
y
:
q
,
heads
:
make
([]
*
queryResults
,
0
,
len
(
dses
)),
heads
:
make
([]
*
queryResults
,
0
,
len
(
dses
)),
}
}
...
@@ -242,6 +249,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
...
@@ -242,6 +249,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
qi
:=
q
qi
:=
q
qi
.
Prefix
=
rest
.
String
()
qi
.
Prefix
=
rest
.
String
()
results
,
err
:=
dstore
.
Query
(
qi
)
results
,
err
:=
dstore
.
Query
(
qi
)
if
err
!=
nil
{
if
err
!=
nil
{
_
=
queries
.
close
()
_
=
queries
.
close
()
return
nil
,
err
return
nil
,
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment