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-ds-flatfs
Commits
be314e51
Commit
be314e51
authored
8 years ago
by
Jeromy Johnson
Committed by
GitHub
8 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3 from ipfs/kevina/faster-query
Improve Query Perforamance
parents
f5bb6094
ce88f7a3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
26 deletions
+57
-26
flatfs.go
flatfs.go
+57
-26
No files found.
flatfs.go
View file @
be314e51
...
...
@@ -312,32 +312,7 @@ func (fs *Datastore) Query(q query.Query) (query.Results, error) {
reschan
:=
make
(
chan
query
.
Result
,
query
.
KeysOnlyBufSize
)
go
func
()
{
defer
close
(
reschan
)
err
:=
filepath
.
Walk
(
fs
.
path
,
func
(
path
string
,
info
os
.
FileInfo
,
err
error
)
error
{
if
os
.
IsNotExist
(
err
)
{
return
nil
}
if
err
!=
nil
{
log
.
Errorf
(
"Walk func in Query got error: %v"
,
err
)
return
err
}
if
!
info
.
Mode
()
.
IsRegular
()
||
strings
.
HasPrefix
(
info
.
Name
(),
"."
)
{
return
nil
}
key
,
ok
:=
fs
.
decode
(
info
.
Name
())
if
!
ok
{
log
.
Warning
(
"failed to decode entry in flatfs"
)
return
nil
}
reschan
<-
query
.
Result
{
Entry
:
query
.
Entry
{
Key
:
key
.
String
(),
},
}
return
nil
})
err
:=
fs
.
walkTopLevel
(
fs
.
path
,
reschan
)
if
err
!=
nil
{
log
.
Warning
(
"walk failed: "
,
err
)
}
...
...
@@ -345,6 +320,62 @@ func (fs *Datastore) Query(q query.Query) (query.Results, error) {
return
query
.
ResultsWithChan
(
q
,
reschan
),
nil
}
func
(
fs
*
Datastore
)
walkTopLevel
(
path
string
,
reschan
chan
query
.
Result
)
error
{
dir
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
err
}
defer
dir
.
Close
()
names
,
err
:=
dir
.
Readdirnames
(
-
1
)
if
err
!=
nil
{
return
err
}
for
_
,
dir
:=
range
names
{
if
len
(
dir
)
==
0
||
dir
[
0
]
==
'.'
{
continue
}
err
=
fs
.
walk
(
filepath
.
Join
(
path
,
dir
),
reschan
)
if
err
!=
nil
{
return
err
}
}
return
nil
}
func
(
fs
*
Datastore
)
walk
(
path
string
,
reschan
chan
query
.
Result
)
error
{
dir
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
err
}
defer
dir
.
Close
()
names
,
err
:=
dir
.
Readdirnames
(
-
1
)
if
err
!=
nil
{
return
err
}
for
_
,
fn
:=
range
names
{
if
len
(
fn
)
==
0
||
fn
[
0
]
==
'.'
{
continue
}
key
,
ok
:=
fs
.
decode
(
fn
)
if
!
ok
{
log
.
Warning
(
"failed to decode entry in flatfs"
)
continue
}
reschan
<-
query
.
Result
{
Entry
:
query
.
Entry
{
Key
:
key
.
String
(),
},
}
}
return
nil
}
func
(
fs
*
Datastore
)
Close
()
error
{
return
nil
}
...
...
This diff is collapsed.
Click to expand it.
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