Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pascal Engélibert
duniter
Commits
96a45e31
Commit
96a45e31
authored
Nov 02, 2015
by
Cédric Moreau
Browse files
Optimisations for /lockchain/current (#197)
parent
ee085835
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/lib/dal/fileDALs/BlockDAL.js
View file @
96a45e31
...
...
@@ -13,18 +13,16 @@ function BlockDAL(fileDAL, loki) {
let
collection
=
loki
.
getCollection
(
'
blocks
'
)
||
loki
.
addCollection
(
'
blocks
'
,
{
indices
:
[
'
fork
'
,
'
number
'
,
'
hash
'
]
});
let
blocksDB
=
getView
();
let
udView
=
collection
.
addDynamicView
(
'
udView
'
);
udView
.
applyFind
({
$and
:
[{
fork
:
false
,
}]
});
udView
.
applySimpleSort
(
'
number
'
,
true
);
let
current
=
null
;
this
.
init
=
()
=>
null
;
this
.
getCurrent
=
()
=>
Q
(
blocksDB
.
branchResultset
().
simplesort
(
'
number
'
,
true
).
limit
(
1
).
data
()[
0
]);
this
.
getCurrent
=
()
=>
{
if
(
!
current
)
{
current
=
blocksDB
.
branchResultset
().
simplesort
(
'
number
'
,
true
).
limit
(
1
).
data
()[
0
];
}
return
Q
(
current
);
};
this
.
getBlock
=
(
number
)
=>
Q
(
blocksDB
.
branchResultset
().
find
({
number
:
parseInt
(
number
)
}).
data
()[
0
]);
...
...
@@ -53,7 +51,14 @@ function BlockDAL(fileDAL, loki) {
return
Q
(
blocksOfIssuer
[
0
]);
};
this
.
saveBunch
=
(
blocks
)
=>
{
collection
.
insert
(
blocks
);
};
this
.
saveBlock
=
(
block
)
=>
{
if
(
!
current
||
current
.
number
<
block
.
number
)
{
current
=
block
;
}
block
.
fork
=
!!
fileDAL
.
parentDAL
;
let
existing
;
existing
=
collection
.
find
({
...
...
app/service/BlockchainService.js
View file @
96a45e31
...
...
@@ -1414,7 +1414,7 @@ function BlockchainService (conf, mainDAL, pair) {
});
});
}
mainDAL
.
blockDAL
.
collection
.
insert
(
blocks
);
mainDAL
.
blockDAL
.
saveBunch
(
blocks
);
//console.log('Saved');
});
...
...
Write
Preview
Supports
Markdown
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