-Refactored handling of blocked claims.
-Changed deletes to be queued and refactored. -Added logging. -Removed commented debug code. -Added Spent and Expired bid_state handling.
This commit is contained in:
parent
78e26b2e6e
commit
cd0f980904
1 changed files with 31 additions and 26 deletions
|
@ -26,7 +26,7 @@ const eclient = new elasticsearch.Client({
|
||||||
});
|
});
|
||||||
const queue = new ElasticQueue({elastic: eclient});
|
const queue = new ElasticQueue({elastic: eclient});
|
||||||
|
|
||||||
// Check that our cache file exist.
|
// Check that our syncState file exist.
|
||||||
fileExists(path.join(appRoot.path, 'syncState.json'), (err, exists) => {
|
fileExists(path.join(appRoot.path, 'syncState.json'), (err, exists) => {
|
||||||
if (err) { throw err }
|
if (err) { throw err }
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
|
@ -48,38 +48,20 @@ export async function claimSync () {
|
||||||
status.info = 'addingClaimsToElastic';
|
status.info = 'addingClaimsToElastic';
|
||||||
for (let claim of claims) {
|
for (let claim of claims) {
|
||||||
claim.value = JSON.parse(claim.value).Claim;
|
claim.value = JSON.parse(claim.value).Claim;
|
||||||
// console.log('NEW: ' + JSON.stringify(claim));
|
|
||||||
// console.log('--------------------------------------------');
|
|
||||||
// var imprtr = require('../importer');
|
|
||||||
// let oldvalue = await imprtr.getValue(claim.transaction_by_hash_id, claim.vout);
|
|
||||||
// oldvalue = JSON.parse(oldvalue);
|
|
||||||
// console.log('OLD: ' + JSON.stringify(oldvalue));
|
|
||||||
// console.log('--------------------------------------------');
|
|
||||||
if (claim.name && claim.value) {
|
if (claim.name && claim.value) {
|
||||||
claim.suggest_name = {
|
claim.suggest_name = {
|
||||||
input : '' + claim.name + '',
|
input : '' + claim.name + '',
|
||||||
weight: '30',
|
weight: '30',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pushElastic(claim);
|
if (claim.bid_state === 'Spent' || claim.bid_state === 'Expired') {
|
||||||
|
deleteFromElastic(claim.claimId);
|
||||||
|
} else {
|
||||||
|
pushElastic(claim);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
winston.log('info', '[Importer] Pushed ' + claims.length + ' claims to elastic search');
|
winston.log('info', '[Importer] Pushed ' + claims.length + ' claims to elastic search');
|
||||||
winston.log('info', '[Importer] Removing blocked claims from search!');
|
deleteBlockedClaims();
|
||||||
let blockedOutputsResponse = await getBlockedOutpoints();
|
|
||||||
let outpointlist = JSON.parse(blockedOutputsResponse);
|
|
||||||
for (let outpoint of outpointlist.data.outpoints) {
|
|
||||||
let claimid = util.OutpointToClaimId(outpoint);
|
|
||||||
console.log('Deleting ClaimId: ' + claimid);
|
|
||||||
eclient.delete({
|
|
||||||
index: 'claims',
|
|
||||||
type : 'claim',
|
|
||||||
id : claimid,
|
|
||||||
}, function (error, response) {
|
|
||||||
if (error) {
|
|
||||||
winston.log(error, response);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
syncState.LastSyncTime = new Date().toISOString().slice(0, 19).replace('T', ' ');
|
syncState.LastSyncTime = new Date().toISOString().slice(0, 19).replace('T', ' ');
|
||||||
await saveJSON(path.join(appRoot.path, 'syncState.json'), syncState);
|
await saveJSON(path.join(appRoot.path, 'syncState.json'), syncState);
|
||||||
status.info = 'upToDate';
|
status.info = 'upToDate';
|
||||||
|
@ -97,8 +79,29 @@ export function getStats () {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function deleteBlockedClaims () {
|
||||||
|
winston.log('info', '[Importer] Removing blocked claims from search!');
|
||||||
|
let blockedOutputsResponse = await getBlockedOutpoints();
|
||||||
|
let outpointlist = JSON.parse(blockedOutputsResponse);
|
||||||
|
for (let outpoint of outpointlist.data.outpoints) {
|
||||||
|
let claimid = util.OutpointToClaimId(outpoint);
|
||||||
|
deleteFromElastic(claimid);
|
||||||
|
}
|
||||||
|
winston.log('info', '[Importer] Done processing blocked claims!');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteFromElastic (claimid) {
|
||||||
|
return new Promise(async(resolve, reject) => {
|
||||||
|
queue.push({
|
||||||
|
index: 'claims',
|
||||||
|
type : 'claim',
|
||||||
|
id : claimid,
|
||||||
|
body : {},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function pushElastic (claim) {
|
async function pushElastic (claim) {
|
||||||
console.log('Pushing To Elastic Search claimId:' + claim.claimId);
|
|
||||||
return new Promise(async(resolve, reject) => {
|
return new Promise(async(resolve, reject) => {
|
||||||
queue.push({
|
queue.push({
|
||||||
index: 'claims',
|
index: 'claims',
|
||||||
|
@ -143,6 +146,7 @@ function getBlockedOutpoints () {
|
||||||
resolve(htmlString);
|
resolve(htmlString);
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
|
winston.log('error', '[Importer] Error getting blocked outpoints. ' + err);
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -168,6 +172,7 @@ function getClaimsSince (time) {
|
||||||
resolve(htmlString);
|
resolve(htmlString);
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
|
winston.log('error', '[Importer] Error getting updated claims. ' + err);
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue