1.20.14 • Published 5 months ago
@ocap/indexdb-prune v1.20.14
IndexDB Prune Tool
This tool helps identify and remove records from Elasticsearch-based IndexDB that do not exist in the StateDB. The process is now streamlined with an API-based approach for better integration with other systems.
Usage
Programmatic API
You can use the tool programmatically by importing it:
const pruneIndexDB = require('@ocap/tools-indexdb-prune');
async function runPrune() {
try {
const deletedRecords = await pruneIndexDB();
console.log('Pruning completed successfully');
console.log('Deleted records:', deletedRecords);
// deletedRecords format: { account: ['id1', 'id2'], tx: ['txid1', 'txid2'] }
} catch (err) {
console.error('Pruning failed:', err);
}
}
runPrune();
Process
The tool now performs these operations in a single flow:
- Establishes connections to both IndexDB (Elasticsearch) and StateDB (Dolt)
- Scans all tables in IndexDB (tx, account, asset, delegation, token, factory, stake, rollup, rollupBlock)
- For each record, verifies if it exists in StateDB
- Automatically deletes records that exist in IndexDB but not in StateDB
- Returns a map of deleted record IDs by table
Return Value
The function returns an object with tables as keys and arrays of deleted IDs as values:
{
account: ['accountId1', 'accountId2', ...],
tx: ['txId1', 'txId2', ...],
asset: ['assetId1', 'assetId2', ...],
// other tables...
}