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
7a8c70e5
Unverified
Commit
7a8c70e5
authored
Mar 21, 2019
by
Michael Avila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add another naive solution for offset
parent
28e5b7b1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
2 deletions
+57
-2
mount/mount.go
mount/mount.go
+5
-1
mount/mount_test.go
mount/mount_test.go
+51
-0
query/query_impl.go
query/query_impl.go
+1
-1
No files found.
mount/mount.go
View file @
7a8c70e5
...
...
@@ -230,6 +230,10 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
prefix
:=
ds
.
NewKey
(
q
.
Prefix
)
dses
,
mounts
,
rests
:=
d
.
lookupAll
(
prefix
)
// offset needs to be applied after the results are aggregated
offset
:=
q
.
Offset
q
.
Offset
=
0
queries
:=
&
querySet
{
query
:
q
,
heads
:
make
([]
*
queryResults
,
0
,
len
(
dses
)),
...
...
@@ -256,7 +260,7 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
Close
:
queries
.
close
,
})
return
query
.
NaiveLimit
(
q
r
,
q
.
Limit
),
nil
return
query
.
NaiveLimit
(
q
uery
.
NaiveOffset
(
qr
,
offset
)
,
q
.
Limit
),
nil
}
func
(
d
*
Datastore
)
Close
()
error
{
...
...
mount/mount_test.go
View file @
7a8c70e5
...
...
@@ -401,6 +401,57 @@ func TestQueryLimitCrossWithSort(t *testing.T) {
}
}
func
TestQueryLimitAndOffsetCrossWithSort
(
t
*
testing
.
T
)
{
mapds1
:=
sync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
mapds2
:=
sync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
mapds3
:=
sync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
m
:=
mount
.
New
([]
mount
.
Mount
{
{
Prefix
:
datastore
.
NewKey
(
"/rok"
),
Datastore
:
mapds1
},
{
Prefix
:
datastore
.
NewKey
(
"/zoo"
),
Datastore
:
mapds2
},
{
Prefix
:
datastore
.
NewKey
(
"/noop"
),
Datastore
:
mapds3
},
})
m
.
Put
(
datastore
.
NewKey
(
"/rok/0"
),
[]
byte
(
"ghi"
))
m
.
Put
(
datastore
.
NewKey
(
"/zoo/0"
),
[]
byte
(
"123"
))
m
.
Put
(
datastore
.
NewKey
(
"/rok/1"
),
[]
byte
(
"def"
))
m
.
Put
(
datastore
.
NewKey
(
"/zoo/1"
),
[]
byte
(
"167"
))
m
.
Put
(
datastore
.
NewKey
(
"/zoo/2"
),
[]
byte
(
"345"
))
m
.
Put
(
datastore
.
NewKey
(
"/rok/3"
),
[]
byte
(
"abc"
))
m
.
Put
(
datastore
.
NewKey
(
"/zoo/3"
),
[]
byte
(
"456"
))
q
:=
query
.
Query
{
Limit
:
3
,
Offset
:
2
,
Orders
:
[]
query
.
Order
{
query
.
OrderByKey
{}}}
res
,
err
:=
m
.
Query
(
q
)
if
err
!=
nil
{
t
.
Fatalf
(
"Query fail: %v
\n
"
,
err
)
}
entries
,
err
:=
res
.
Rest
()
if
err
!=
nil
{
t
.
Fatalf
(
"Query Results.Rest fail: %v
\n
"
,
err
)
}
expect
:=
[]
string
{
"/rok/3"
,
"/zoo/0"
,
"/zoo/1"
,
}
if
len
(
entries
)
!=
len
(
expect
)
{
t
.
Fatalf
(
"expected %d entries, but got %d"
,
len
(
expect
),
len
(
entries
))
}
for
i
,
e
:=
range
expect
{
if
e
!=
entries
[
i
]
.
Key
{
t
.
Errorf
(
"expected key %s, but got %s"
,
e
,
entries
[
i
]
.
Key
)
}
}
err
=
res
.
Close
()
if
err
!=
nil
{
t
.
Errorf
(
"result.Close failed %d"
,
err
)
}
}
func
TestLookupPrio
(
t
*
testing
.
T
)
{
mapds0
:=
datastore
.
NewMapDatastore
()
mapds1
:=
datastore
.
NewMapDatastore
()
...
...
query/query_impl.go
View file @
7a8c70e5
...
...
@@ -74,7 +74,7 @@ func NaiveOffset(qr Results, offset int) Results {
}
}()
return
DerivedResults
(
qr
,
ch
)
return
ResultsWithChan
(
qr
.
Query
()
,
ch
)
}
// NaiveOrder reorders results according to given orders.
...
...
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