Skip to content
Snippets Groups Projects
Commit e11261d6 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[fix] fix format using Prettier

parent 42913bae
Branches
No related tags found
1 merge request!1420[fix] Optimize access to sources by pubkey, using specific index
...@@ -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 + ")"),
......
...@@ -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) => {
......
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);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment