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
9af81aec
Commit
9af81aec
authored
2 years ago
by
Benoit Lavenier
Browse files
Options
Downloads
Patches
Plain Diff
fix(format)
parent
0dfa8abd
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1429
fix(1442): Optimize BMA /tx/history
Pipeline
#32240
failed
2 years ago
Stage: tests
Stage: package
Stage: integration
Changes
1
Pipelines
3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/lib/dal/indexDAL/sqlite/SqliteTransactions.ts
+61
-19
61 additions, 19 deletions
app/lib/dal/indexDAL/sqlite/SqliteTransactions.ts
with
61 additions
and
19 deletions
app/lib/dal/indexDAL/sqlite/SqliteTransactions.ts
+
61
−
19
View file @
9af81aec
...
@@ -29,10 +29,18 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
...
@@ -29,10 +29,18 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
inputs
:
new
SqlNullableFieldDefinition
(
"
JSON
"
,
false
),
inputs
:
new
SqlNullableFieldDefinition
(
"
JSON
"
,
false
),
unlocks
:
new
SqlNullableFieldDefinition
(
"
JSON
"
,
false
),
unlocks
:
new
SqlNullableFieldDefinition
(
"
JSON
"
,
false
),
outputs
:
new
SqlNullableFieldDefinition
(
"
JSON
"
,
false
),
outputs
:
new
SqlNullableFieldDefinition
(
"
JSON
"
,
false
),
issuer
:
new
SqlNullableFieldDefinition
(
"
VARCHAR
"
,
true
,
50
),
/* computed column - need by getTxHistoryXxx() */
issuer
:
new
SqlNullableFieldDefinition
(
"
VARCHAR
"
,
true
,
50
)
/* computed column - need by getTxHistoryXxx() */
,
issuers
:
new
SqlNullableFieldDefinition
(
"
JSON
"
,
false
),
issuers
:
new
SqlNullableFieldDefinition
(
"
JSON
"
,
false
),
signatures
:
new
SqlNullableFieldDefinition
(
"
JSON
"
,
false
),
signatures
:
new
SqlNullableFieldDefinition
(
"
JSON
"
,
false
),
recipient
:
new
SqlNullableFieldDefinition
(
"
VARCHAR
"
,
true
,
50
),
/* computed column - need by getTxHistoryXxx() */
recipient
:
new
SqlNullableFieldDefinition
(
"
VARCHAR
"
,
true
,
50
)
/* computed column - need by getTxHistoryXxx() */
,
recipients
:
new
SqlNullableFieldDefinition
(
"
JSON
"
,
false
),
recipients
:
new
SqlNullableFieldDefinition
(
"
JSON
"
,
false
),
written
:
new
SqlNotNullableFieldDefinition
(
"
BOOLEAN
"
,
true
),
written
:
new
SqlNotNullableFieldDefinition
(
"
BOOLEAN
"
,
true
),
removed
:
new
SqlNotNullableFieldDefinition
(
"
BOOLEAN
"
,
true
),
removed
:
new
SqlNotNullableFieldDefinition
(
"
BOOLEAN
"
,
true
),
...
@@ -93,7 +101,7 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
...
@@ -93,7 +101,7 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
@
MonitorExecutionTime
()
@
MonitorExecutionTime
()
async
saveBatch
(
records
:
DBTx
[]):
Promise
<
void
>
{
async
saveBatch
(
records
:
DBTx
[]):
Promise
<
void
>
{
if
(
records
.
length
)
{
if
(
records
.
length
)
{
await
this
.
removeByHashBatch
(
records
.
map
(
t
=>
t
.
hash
));
await
this
.
removeByHashBatch
(
records
.
map
(
(
t
)
=>
t
.
hash
));
await
this
.
insertBatch
(
records
);
await
this
.
insertBatch
(
records
);
}
}
}
}
...
@@ -172,8 +180,18 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
...
@@ -172,8 +180,18 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
to
:
number
to
:
number
):
Promise
<
{
sent
:
DBTx
[];
received
:
DBTx
[]
}
>
{
):
Promise
<
{
sent
:
DBTx
[];
received
:
DBTx
[]
}
>
{
return
{
return
{
sent
:
await
this
.
getLinkedWithIssuerByRange
(
'
block_number
'
,
pubkey
,
from
,
to
),
sent
:
await
this
.
getLinkedWithIssuerByRange
(
received
:
await
this
.
getLinkedWithRecipientByRange
(
'
block_number
'
,
pubkey
,
from
,
to
),
"
block_number
"
,
pubkey
,
from
,
to
),
received
:
await
this
.
getLinkedWithRecipientByRange
(
"
block_number
"
,
pubkey
,
from
,
to
),
};
};
}
}
...
@@ -183,8 +201,13 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
...
@@ -183,8 +201,13 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
to
:
number
to
:
number
):
Promise
<
{
sent
:
DBTx
[];
received
:
DBTx
[]
}
>
{
):
Promise
<
{
sent
:
DBTx
[];
received
:
DBTx
[]
}
>
{
return
{
return
{
sent
:
await
this
.
getLinkedWithIssuerByRange
(
'
time
'
,
pubkey
,
from
,
to
),
sent
:
await
this
.
getLinkedWithIssuerByRange
(
"
time
"
,
pubkey
,
from
,
to
),
received
:
await
this
.
getLinkedWithRecipientByRange
(
'
time
'
,
pubkey
,
from
,
to
)
received
:
await
this
.
getLinkedWithRecipientByRange
(
"
time
"
,
pubkey
,
from
,
to
),
};
};
}
}
...
@@ -198,7 +221,8 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
...
@@ -198,7 +221,8 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
}
}
getLinkedWithIssuer
(
pubkey
:
string
):
Promise
<
DBTx
[]
>
{
getLinkedWithIssuer
(
pubkey
:
string
):
Promise
<
DBTx
[]
>
{
return
this
.
findEntities
(
`SELECT * FROM txs
return
this
.
findEntities
(
`SELECT * FROM txs
WHERE written
WHERE written
AND (
AND (
issuer = ?
issuer = ?
...
@@ -208,8 +232,14 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
...
@@ -208,8 +232,14 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
);
);
}
}
getLinkedWithIssuerByRange
(
rangeFieldName
:
keyof
DBTx
,
pubkey
:
string
,
from
:
number
,
to
:
number
):
Promise
<
DBTx
[]
>
{
getLinkedWithIssuerByRange
(
return
this
.
findEntities
(
`SELECT * FROM txs
rangeFieldName
:
keyof
DBTx
,
pubkey
:
string
,
from
:
number
,
to
:
number
):
Promise
<
DBTx
[]
>
{
return
this
.
findEntities
(
`SELECT * FROM txs
WHERE written
WHERE written
AND (
AND (
issuer = ?
issuer = ?
...
@@ -222,7 +252,8 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
...
@@ -222,7 +252,8 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
}
}
getLinkedWithRecipient
(
pubkey
:
string
):
Promise
<
DBTx
[]
>
{
getLinkedWithRecipient
(
pubkey
:
string
):
Promise
<
DBTx
[]
>
{
return
this
.
findEntities
(
`SELECT * FROM txs
return
this
.
findEntities
(
`SELECT * FROM txs
WHERE written
WHERE written
AND (
AND (
recipient = ?
recipient = ?
...
@@ -232,8 +263,14 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
...
@@ -232,8 +263,14 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
);
);
}
}
getLinkedWithRecipientByRange
(
rangeColumnName
:
string
,
pubkey
:
string
,
from
:
number
,
to
:
number
):
Promise
<
DBTx
[]
>
{
getLinkedWithRecipientByRange
(
return
this
.
findEntities
(
`SELECT * FROM txs
rangeColumnName
:
string
,
pubkey
:
string
,
from
:
number
,
to
:
number
):
Promise
<
DBTx
[]
>
{
return
this
.
findEntities
(
`SELECT * FROM txs
WHERE written
WHERE written
AND (
AND (
recipient = ?
recipient = ?
...
@@ -246,7 +283,8 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
...
@@ -246,7 +283,8 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
}
}
getPendingWithIssuer
(
pubkey
:
string
):
Promise
<
DBTx
[]
>
{
getPendingWithIssuer
(
pubkey
:
string
):
Promise
<
DBTx
[]
>
{
return
this
.
findEntities
(
`SELECT * FROM txs
return
this
.
findEntities
(
`SELECT * FROM txs
WHERE NOT written
WHERE NOT written
AND (
AND (
issuer = ?
issuer = ?
...
@@ -257,7 +295,8 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
...
@@ -257,7 +295,8 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
}
}
getPendingWithRecipient
(
pubkey
:
string
):
Promise
<
DBTx
[]
>
{
getPendingWithRecipient
(
pubkey
:
string
):
Promise
<
DBTx
[]
>
{
return
this
.
findEntities
(
`SELECT * FROM txs
return
this
.
findEntities
(
`SELECT * FROM txs
WHERE NOT written
WHERE NOT written
AND (
AND (
recipient = ?
recipient = ?
...
@@ -268,7 +307,7 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
...
@@ -268,7 +307,7 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
}
}
async
existsByHash
(
hash
:
string
):
Promise
<
boolean
>
{
async
existsByHash
(
hash
:
string
):
Promise
<
boolean
>
{
return
(
await
this
.
countBy
(
'
hash
'
,
hash
))
>
0
;
return
(
await
this
.
countBy
(
"
hash
"
,
hash
))
>
0
;
}
}
async
getTX
(
hash
:
string
):
Promise
<
DBTx
>
{
async
getTX
(
hash
:
string
):
Promise
<
DBTx
>
{
...
@@ -298,7 +337,10 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
...
@@ -298,7 +337,10 @@ export class SqliteTransactions extends SqliteTable<DBTx> implements TxsDAO {
// Delete by slice of 500 items (because SQLite IN operator is limited)
// Delete by slice of 500 items (because SQLite IN operator is limited)
while
(
i
<
hashArray
.
length
-
1
)
{
while
(
i
<
hashArray
.
length
-
1
)
{
const
slice
=
hashArray
.
slice
(
i
,
i
+
500
);
const
slice
=
hashArray
.
slice
(
i
,
i
+
500
);
await
this
.
driver
.
sqlWrite
(
`DELETE FROM txs WHERE hash IN (
${
slice
.
map
(
_
=>
'
?
'
).
join
(
'
,
'
)}
)`
,
slice
);
await
this
.
driver
.
sqlWrite
(
`DELETE FROM txs WHERE hash IN (
${
slice
.
map
((
_
)
=>
"
?
"
).
join
(
"
,
"
)}
)`
,
slice
);
i
+=
500
;
i
+=
500
;
}
}
}
}
...
...
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