Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Commits
e11261d6
Commit
e11261d6
authored
2 years ago
by
Benoit Lavenier
Browse files
Options
Downloads
Patches
Plain Diff
[fix] fix format using Prettier
parent
42913bae
Branches
Branches containing commit
No related tags found
1 merge request
!1420
[fix] Optimize access to sources by pubkey, using specific index
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/lib/common-libs/constants.ts
+2
-2
2 additions, 2 deletions
app/lib/common-libs/constants.ts
app/lib/dal/fileDAL.ts
+1
-1
1 addition, 1 deletion
app/lib/dal/fileDAL.ts
app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts
+47
-26
47 additions, 26 deletions
app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts
with
50 additions
and
29 deletions
app/lib/common-libs/constants.ts
+
2
−
2
View file @
e11261d6
...
@@ -536,7 +536,7 @@ export const CommonConstants = {
...
@@ -536,7 +536,7 @@ export const CommonConstants = {
INLINE_COMMENT
:
exact
(
COMMENT
),
INLINE_COMMENT
:
exact
(
COMMENT
),
OUTPUT_CONDITION
:
exact
(
CONDITIONS
),
OUTPUT_CONDITION
:
exact
(
CONDITIONS
),
OUTPUT_CONDITION_SIG_PUBKEY
:
find
(
CONDITION_SIG_PUBKEY
),
OUTPUT_CONDITION_SIG_PUBKEY
:
find
(
CONDITION_SIG_PUBKEY
),
OUTPUT_CONDITION_SIG_PUBKEY_UNIQUE
:
exact
(
CONDITION_SIG_PUBKEY
)
OUTPUT_CONDITION_SIG_PUBKEY_UNIQUE
:
exact
(
CONDITION_SIG_PUBKEY
)
,
},
},
PEER
:
{
PEER
:
{
BLOCK
:
find
(
"
Block: (
"
+
INTEGER
+
"
-
"
+
FINGERPRINT
+
"
)
"
),
BLOCK
:
find
(
"
Block: (
"
+
INTEGER
+
"
-
"
+
FINGERPRINT
+
"
)
"
),
...
...
This diff is collapsed.
Click to expand it.
app/lib/dal/fileDAL.ts
+
1
−
1
View file @
e11261d6
...
@@ -472,7 +472,7 @@ export class FileDAL implements ServerDAO {
...
@@ -472,7 +472,7 @@ export class FileDAL implements ServerDAO {
async
getAvailableSourcesByPubkey
(
pubkey
:
string
):
Promise
<
HttpSource
[]
>
{
async
getAvailableSourcesByPubkey
(
pubkey
:
string
):
Promise
<
HttpSource
[]
>
{
const
[
txAvailable
,
sources
]
=
await
Promise
.
all
([
const
[
txAvailable
,
sources
]
=
await
Promise
.
all
([
this
.
sindexDAL
.
getAvailableForPubkey
(
pubkey
),
this
.
sindexDAL
.
getAvailableForPubkey
(
pubkey
),
this
.
dividendDAL
.
getUDSources
(
pubkey
)
this
.
dividendDAL
.
getUDSources
(
pubkey
)
,
]);
]);
return
sources
return
sources
.
map
((
d
)
=>
{
.
map
((
d
)
=>
{
...
...
This diff is collapsed.
Click to expand it.
app/lib/dal/indexDAL/leveldb/LevelDBSindex.ts
+
47
−
26
View file @
e11261d6
import
{
MonitorExecutionTime
}
from
"
../../../debug/MonitorExecutionTime
"
;
import
{
MonitorExecutionTime
}
from
"
../../../debug/MonitorExecutionTime
"
;
import
{
FullSindexEntry
,
Indexer
,
SimpleTxEntryForWallet
,
SimpleTxInput
,
SindexEntry
,}
from
"
../../../indexer
"
;
import
{
FullSindexEntry
,
Indexer
,
SimpleTxEntryForWallet
,
SimpleTxInput
,
SindexEntry
,
}
from
"
../../../indexer
"
;
import
{
LevelUp
}
from
"
levelup
"
;
import
{
LevelUp
}
from
"
levelup
"
;
import
{
LevelDBTable
}
from
"
./LevelDBTable
"
;
import
{
LevelDBTable
}
from
"
./LevelDBTable
"
;
import
{
SIndexDAO
}
from
"
../abstract/SIndexDAO
"
;
import
{
SIndexDAO
}
from
"
../abstract/SIndexDAO
"
;
...
@@ -130,11 +136,13 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
...
@@ -130,11 +136,13 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
}[]
}[]
>
{
>
{
const
forSimpleConditions
=
await
this
.
getForConditions
(
`SIG(
${
pubkey
}
)`
);
const
forSimpleConditions
=
await
this
.
getForConditions
(
`SIG(
${
pubkey
}
)`
);
const
forComplexConditions
=
await
this
.
getForComplexeConditionPubkey
(
pubkey
);
const
forComplexConditions
=
await
this
.
getForComplexeConditionPubkey
(
const
reduced
=
Indexer
.
DUP_HELPERS
.
reduceBy
(
forSimpleConditions
.
concat
(
forComplexConditions
),
[
pubkey
"
identifier
"
,
);
"
pos
"
,
const
reduced
=
Indexer
.
DUP_HELPERS
.
reduceBy
(
]);
forSimpleConditions
.
concat
(
forComplexConditions
),
[
"
identifier
"
,
"
pos
"
]
);
return
reduced
.
filter
((
r
)
=>
!
r
.
consumed
);
return
reduced
.
filter
((
r
)
=>
!
r
.
consumed
);
}
}
...
@@ -270,7 +278,8 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
...
@@ -270,7 +278,8 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
}
}
async
getForComplexeConditionPubkey
(
pubkey
:
string
):
Promise
<
SindexEntry
[]
>
{
async
getForComplexeConditionPubkey
(
pubkey
:
string
):
Promise
<
SindexEntry
[]
>
{
const
ids
=
(
await
this
.
indexOfComplexeConditionForPubkeys
.
getOrNull
(
pubkey
))
||
[];
const
ids
=
(
await
this
.
indexOfComplexeConditionForPubkeys
.
getOrNull
(
pubkey
))
||
[];
const
found
:
SindexEntry
[]
=
[];
const
found
:
SindexEntry
[]
=
[];
for
(
const
id
of
ids
)
{
for
(
const
id
of
ids
)
{
const
entries
=
await
this
.
findByIdentifierAndPos
(
const
entries
=
await
this
.
findByIdentifierAndPos
(
...
@@ -379,7 +388,8 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
...
@@ -379,7 +388,8 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
private
async
trimComplexeConditionPubkey
(
pubkey
:
string
,
id
:
string
)
{
private
async
trimComplexeConditionPubkey
(
pubkey
:
string
,
id
:
string
)
{
// Get all the condition's sources
// Get all the condition's sources
const
existing
=
(
await
this
.
indexOfComplexeConditionForPubkeys
.
getOrNull
(
pubkey
))
||
[];
const
existing
=
(
await
this
.
indexOfComplexeConditionForPubkeys
.
getOrNull
(
pubkey
))
||
[];
// Prune the source from the condition
// Prune the source from the condition
const
trimmed
=
arrayPruneAllCopy
(
existing
,
id
);
const
trimmed
=
arrayPruneAllCopy
(
existing
,
id
);
if
(
trimmed
.
length
)
{
if
(
trimmed
.
length
)
{
...
@@ -496,7 +506,8 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
...
@@ -496,7 +506,8 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
}
}
// Index pubkeys => (identifier + pos)[]
// Index pubkeys => (identifier + pos)[]
for
(
const
k
of
Underscore
.
keys
(
byPubkeys
).
map
(
String
))
{
for
(
const
k
of
Underscore
.
keys
(
byPubkeys
).
map
(
String
))
{
const
existing
=
(
await
this
.
indexOfComplexeConditionForPubkeys
.
getOrNull
(
k
))
||
[];
const
existing
=
(
await
this
.
indexOfComplexeConditionForPubkeys
.
getOrNull
(
k
))
||
[];
const
newSources
=
byPubkeys
[
k
].
map
((
r
)
=>
const
newSources
=
byPubkeys
[
k
].
map
((
r
)
=>
LevelDBSindex
.
trimPartialKey
(
r
.
identifier
,
r
.
pos
)
LevelDBSindex
.
trimPartialKey
(
r
.
identifier
,
r
.
pos
)
);
);
...
@@ -508,7 +519,13 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
...
@@ -508,7 +519,13 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
}
}
private
isComplexCondition
(
condition
:
string
):
boolean
{
private
isComplexCondition
(
condition
:
string
):
boolean
{
return
condition
&&
!
CommonConstants
.
TRANSACTION
.
OUTPUT_CONDITION_SIG_PUBKEY_UNIQUE
.
test
(
condition
)
||
false
;
return
(
(
condition
&&
!
CommonConstants
.
TRANSACTION
.
OUTPUT_CONDITION_SIG_PUBKEY_UNIQUE
.
test
(
condition
))
||
false
);
}
}
/**
/**
* Get all pubkeys used by an output condition (e.g. 'SIG(A) && SIG(B)' will return ['A', 'B']
* Get all pubkeys used by an output condition (e.g. 'SIG(A) && SIG(B)' will return ['A', 'B']
...
@@ -519,7 +536,11 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
...
@@ -519,7 +536,11 @@ export class LevelDBSindex extends LevelDBTable<SindexEntry>
const
pubKeys
:
string
[]
=
[];
const
pubKeys
:
string
[]
=
[];
if
(
!
condition
)
return
pubKeys
;
if
(
!
condition
)
return
pubKeys
;
let
match
:
RegExpExecArray
|
null
;
let
match
:
RegExpExecArray
|
null
;
while
((
match
=
CommonConstants
.
TRANSACTION
.
OUTPUT_CONDITION_SIG_PUBKEY
.
exec
(
condition
))
!==
null
)
{
while
(
(
match
=
CommonConstants
.
TRANSACTION
.
OUTPUT_CONDITION_SIG_PUBKEY
.
exec
(
condition
))
!==
null
)
{
pubKeys
.
push
(
match
[
1
]);
pubKeys
.
push
(
match
[
1
]);
condition
=
condition
.
substring
(
match
.
index
+
match
[
0
].
length
);
condition
=
condition
.
substring
(
match
.
index
+
match
[
0
].
length
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment