Mise à jour de GitLab prévue ce samedi 23 octobre 2021 à partir de 9h00 CET

Commit f62a0b8e authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[enh] sync: allow to disable Loki changesAPI dynamically

parent 11389e85
......@@ -79,6 +79,8 @@ import {cliprogram} from "../common-libs/programOptions"
import {DividendDAO, UDSource} from "./indexDAL/abstract/DividendDAO"
import {LokiDividend} from "./indexDAL/loki/LokiDividend"
import {HttpSource, HttpUD} from "../../modules/bma/lib/dtos"
import {GenericDAO} from "./indexDAL/abstract/GenericDAO"
import {LokiDAO} from "./indexDAL/loki/LokiDAO"
const readline = require('readline')
const indexer = require('../indexer').Indexer
......@@ -133,6 +135,8 @@ export class FileDAL {
cindexDAL:CIndexDAO
dividendDAL:DividendDAO
newDals:{ [k:string]: Initiable }
private dals:(BlockchainArchiveDAO<any>|PeerDAO|WalletDAO|GenericDAO<any>)[]
private daos:LokiDAO[]
loadConfHook: (conf:ConfDTO) => Promise<void>
saveConfHook: (conf:ConfDTO) => Promise<ConfDTO>
......@@ -187,10 +191,30 @@ export class FileDAL {
}
}
public enableChangesAPI() {
this.daos.map(d => d.enableChangesAPI())
}
public disableChangesAPI() {
this.daos.map(d => d.disableChangesAPI())
}
async init(conf:ConfDTO) {
// Init LokiJS
await this.loki.loadDatabase()
const dals = [
this.daos = [
this.blockDAL,
this.txsDAL,
this.peerDAL,
this.walletDAL,
this.bindexDAL,
this.mindexDAL,
this.iindexDAL,
this.sindexDAL,
this.cindexDAL,
this.dividendDAL
]
this.dals = [
this.blockDAL,
this.txsDAL,
this.peerDAL,
......@@ -203,7 +227,7 @@ export class FileDAL {
this.dividendDAL,
this.blockchainArchiveDAL,
]
for (const indexDAL of dals) {
for (const indexDAL of this.dals) {
indexDAL.triggerInit()
}
const dalNames = Underscore.keys(this.newDals);
......
import {Initiable} from "../../sqliteDAL/Initiable"
import {LokiDAO} from "../loki/LokiDAO"
export interface GenericDAO<T> extends Initiable {
export interface GenericDAO<T> extends Initiable, LokiDAO {
/**
* Trigger the initialization of the DAO. Called when the underlying DB is ready.
......
import {Initiable} from "../../sqliteDAL/Initiable"
import {DBPeer} from "../../../db/DBPeer"
import {LokiDAO} from "../loki/LokiDAO"
export interface PeerDAO extends Initiable {
export interface PeerDAO extends Initiable, LokiDAO {
/**
* Trigger the initialization of the DAO. Called when the underlying DB is ready.
......
import {Initiable} from "../../sqliteDAL/Initiable"
import {DBWallet} from "../../../db/DBWallet"
import {LokiDAO} from "../loki/LokiDAO"
export interface WalletDAO extends Initiable {
export interface WalletDAO extends Initiable, LokiDAO {
/**
* Trigger the initialization of the DAO. Called when the underlying DB is ready.
......
import {LokiChainableFind, LokiCollection} from "./LokiTypes"
import {NewLogger} from "../../../logger"
import {getDurationInMicroSeconds, getMicrosecondsTime} from "../../../../ProcessCpuProfiler"
import {getMicrosecondsTime} from "../../../../ProcessCpuProfiler"
const logger = NewLogger()
......@@ -35,4 +35,8 @@ export class LokiProxyCollection<T> implements LokiCollection<T> {
chain(): LokiChainableFind<T> {
return this.collection.chain()
}
setDisableChangesAPI(disable: boolean) {
this.collection.setDisableChangesAPI(disable)
}
}
import {LokiCollection} from "./LokiTypes"
import {LokiProxyCollection} from "./LokiCollection"
import {NewLogger} from "../../../logger"
import {LokiDAO} from "./LokiDAO"
import {cliprogram} from "../../../common-libs/programOptions"
const logger = NewLogger()
export abstract class LokiCollectionManager<T> {
export abstract class LokiCollectionManager<T> implements LokiDAO {
protected collection:LokiCollection<T>
protected collectionIsInitialized: Promise<void>
......@@ -27,6 +28,14 @@ export abstract class LokiCollectionManager<T> {
this.resolveCollection()
}
public enableChangesAPI() {
this.collection.setDisableChangesAPI(false)
}
public disableChangesAPI() {
this.collection.setDisableChangesAPI(true)
}
async init(): Promise<void> {
await this.collectionIsInitialized
logger.info('Collection %s ready', this.collectionName)
......
export interface LokiDAO {
enableChangesAPI(): void
disableChangesAPI(): void
}
......@@ -12,6 +12,8 @@ export interface LokiCollection<T> {
find(criterion:{ [t in keyof T|'$or'|'$and']?: any }): T[]
chain(): LokiChainableFind<T>
setDisableChangesAPI(disable: boolean): void
}
export interface LokiChainableFind<T> {
......
......@@ -54,7 +54,11 @@ export const CrawlerDependency = {
const syncPromise = remote.sync(upTo, chunkLength)
return {
flow: remote,
syncPromise: syncPromise
syncPromise: (async () => {
await server.dal.disableChangesAPI()
await syncPromise
await server.dal.enableChangesAPI()
})()
};
},
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment