Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
1a48e6a9
提交
1a48e6a9
authored
3月 11, 2015
作者:
Tommi Virtanen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Dead code cleanup: remove Range support from blockstore
Nothing uses it, and offset+limit is a bad query mechanism for mutating data.
上级
49732d24
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
10 行增加
和
48 行删除
+10
-48
blockstore.go
blocks/blockstore/blockstore.go
+8
-21
blockstore_test.go
blocks/blockstore/blockstore_test.go
+0
-17
write_cache.go
blocks/blockstore/write_cache.go
+2
-10
没有找到文件。
blocks/blockstore/blockstore.go
浏览文件 @
1a48e6a9
...
...
@@ -33,9 +33,6 @@ type Blockstore interface {
AllKeys
(
ctx
context
.
Context
)
([]
u
.
Key
,
error
)
AllKeysChan
(
ctx
context
.
Context
)
(
<-
chan
u
.
Key
,
error
)
AllKeysRange
(
ctx
context
.
Context
,
offset
int
,
limit
int
)
([]
u
.
Key
,
error
)
AllKeysRangeChan
(
ctx
context
.
Context
,
offset
int
,
limit
int
)
(
<-
chan
u
.
Key
,
error
)
}
func
NewBlockstore
(
d
ds
.
ThreadSafeDatastore
)
Blockstore
{
...
...
@@ -85,22 +82,13 @@ func (s *blockstore) DeleteBlock(k u.Key) error {
return
s
.
datastore
.
Delete
(
k
.
DsKey
())
}
func
(
bs
*
blockstore
)
AllKeys
(
ctx
context
.
Context
)
([]
u
.
Key
,
error
)
{
return
bs
.
AllKeysRange
(
ctx
,
0
,
0
)
}
func
(
bs
*
blockstore
)
AllKeysChan
(
ctx
context
.
Context
)
(
<-
chan
u
.
Key
,
error
)
{
return
bs
.
AllKeysRangeChan
(
ctx
,
0
,
0
)
}
// AllKeysRange runs a query for keys from the blockstore.
// AllKeys runs a query for keys from the blockstore.
// this is very simplistic, in the future, take dsq.Query as a param?
// if offset and limit are 0, they are ignored.
//
// AllKeys
Range
respects context
func
(
bs
*
blockstore
)
AllKeys
Range
(
ctx
context
.
Context
,
offset
int
,
limit
in
t
)
([]
u
.
Key
,
error
)
{
// AllKeys respects context
func
(
bs
*
blockstore
)
AllKeys
(
ctx
context
.
Contex
t
)
([]
u
.
Key
,
error
)
{
ch
,
err
:=
bs
.
AllKeys
RangeChan
(
ctx
,
offset
,
limit
)
ch
,
err
:=
bs
.
AllKeys
Chan
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -112,15 +100,14 @@ func (bs *blockstore) AllKeysRange(ctx context.Context, offset int, limit int) (
return
keys
,
nil
}
// AllKeys
Range
Chan runs a query for keys from the blockstore.
// AllKeysChan runs a query for keys from the blockstore.
// this is very simplistic, in the future, take dsq.Query as a param?
// if offset and limit are 0, they are ignored.
//
// AllKeys
Range
Chan respects context
func
(
bs
*
blockstore
)
AllKeys
RangeChan
(
ctx
context
.
Context
,
offset
int
,
limit
in
t
)
(
<-
chan
u
.
Key
,
error
)
{
// AllKeysChan respects context
func
(
bs
*
blockstore
)
AllKeys
Chan
(
ctx
context
.
Contex
t
)
(
<-
chan
u
.
Key
,
error
)
{
// KeysOnly, because that would be _a lot_ of data.
q
:=
dsq
.
Query
{
KeysOnly
:
true
,
Offset
:
offset
,
Limit
:
limit
}
q
:=
dsq
.
Query
{
KeysOnly
:
true
}
res
,
err
:=
bs
.
datastore
.
Query
(
q
)
if
err
!=
nil
{
return
nil
,
err
...
...
blocks/blockstore/blockstore_test.go
浏览文件 @
1a48e6a9
...
...
@@ -78,23 +78,6 @@ func TestAllKeysSimple(t *testing.T) {
expectMatches
(
t
,
keys
,
keys2
)
}
func
TestAllKeysOffsetAndLimit
(
t
*
testing
.
T
)
{
N
:=
30
bs
,
_
:=
newBlockStoreWithKeys
(
t
,
nil
,
N
)
ctx
:=
context
.
Background
()
keys3
,
err
:=
bs
.
AllKeysRange
(
ctx
,
N
/
3
,
N
/
3
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
for
_
,
k3
:=
range
keys3
{
t
.
Log
(
"found "
,
k3
.
Pretty
())
}
if
len
(
keys3
)
!=
N
/
3
{
t
.
Errorf
(
"keys3 should be: %d != %d"
,
N
/
3
,
len
(
keys3
))
}
}
func
TestAllKeysRespectsContext
(
t
*
testing
.
T
)
{
N
:=
100
...
...
blocks/blockstore/write_cache.go
浏览文件 @
1a48e6a9
...
...
@@ -46,17 +46,9 @@ func (w *writecache) Put(b *blocks.Block) error {
}
func
(
w
*
writecache
)
AllKeys
(
ctx
context
.
Context
)
([]
u
.
Key
,
error
)
{
return
w
.
blockstore
.
AllKeys
Range
(
ctx
,
0
,
0
)
return
w
.
blockstore
.
AllKeys
(
ctx
)
}
func
(
w
*
writecache
)
AllKeysChan
(
ctx
context
.
Context
)
(
<-
chan
u
.
Key
,
error
)
{
return
w
.
blockstore
.
AllKeysRangeChan
(
ctx
,
0
,
0
)
}
func
(
w
*
writecache
)
AllKeysRange
(
ctx
context
.
Context
,
offset
int
,
limit
int
)
([]
u
.
Key
,
error
)
{
return
w
.
blockstore
.
AllKeysRange
(
ctx
,
offset
,
limit
)
}
func
(
w
*
writecache
)
AllKeysRangeChan
(
ctx
context
.
Context
,
offset
int
,
limit
int
)
(
<-
chan
u
.
Key
,
error
)
{
return
w
.
blockstore
.
AllKeysRangeChan
(
ctx
,
offset
,
limit
)
return
w
.
blockstore
.
AllKeysChan
(
ctx
)
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论