Merge pull request #625 from lbryio/chainquery-fixes
Fix exceptions and incorrect logic around chainquery
This commit is contained in:
commit
b1c2ea9e72
8 changed files with 39 additions and 21 deletions
|
@ -275,6 +275,7 @@ var ClaimModel = (sequelize, {
|
||||||
BOOLEAN,
|
BOOLEAN,
|
||||||
DATE,
|
DATE,
|
||||||
DECIMAL,
|
DECIMAL,
|
||||||
|
ENUM,
|
||||||
INTEGER,
|
INTEGER,
|
||||||
STRING,
|
STRING,
|
||||||
TEXT,
|
TEXT,
|
||||||
|
@ -378,12 +379,8 @@ var ClaimModel = (sequelize, {
|
||||||
type: STRING,
|
type: STRING,
|
||||||
set() { },
|
set() { },
|
||||||
},
|
},
|
||||||
is_filtered: {
|
|
||||||
type: BOOLEAN,
|
|
||||||
set() { },
|
|
||||||
},
|
|
||||||
bid_state: {
|
bid_state: {
|
||||||
type: STRING,
|
type: ENUM('Active', 'Expired', 'Controlling', 'Spent', 'Accepted'),
|
||||||
set() { },
|
set() { },
|
||||||
},
|
},
|
||||||
created_at: {
|
created_at: {
|
||||||
|
@ -836,7 +833,22 @@ const isShortClaimId = (claimId) => {
|
||||||
return (claimId && (claimId.length < 40));
|
return (claimId && (claimId.length < 40));
|
||||||
};
|
};
|
||||||
|
|
||||||
var claimQueries = (db, table) => ({
|
var claimQueries = (db, table, sequelize) => ({
|
||||||
|
|
||||||
|
getClaimChannelName: async (publisher_id) => {
|
||||||
|
return await table.findAll({
|
||||||
|
where : { claim_id: publisher_id },
|
||||||
|
attributes: ['name'],
|
||||||
|
}).then(result => {
|
||||||
|
if(result.length === 0) {
|
||||||
|
throw new Error(`no record found for ${claimId}`);
|
||||||
|
} else if(result.length !== 1) {
|
||||||
|
logger$1.warn(`more than one record matches ${claimId} in db.Claim`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result[0].name;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
getShortClaimIdFromLongClaimId: async (claimId, claimName) => {
|
getShortClaimIdFromLongClaimId: async (claimId, claimName) => {
|
||||||
logger$1.debug(`claim.getShortClaimIdFromLongClaimId for ${claimName}#${claimId}`);
|
logger$1.debug(`claim.getShortClaimIdFromLongClaimId for ${claimName}#${claimId}`);
|
||||||
|
@ -857,7 +869,6 @@ var claimQueries = (db, table) => ({
|
||||||
return await table.findAll({
|
return await table.findAll({
|
||||||
where: { publisher_id: channelClaimId },
|
where: { publisher_id: channelClaimId },
|
||||||
order: [['height', 'DESC']],
|
order: [['height', 'DESC']],
|
||||||
raw : false, // returns an array of only data, not an array of instances
|
|
||||||
})
|
})
|
||||||
.then(channelClaimsArray => {
|
.then(channelClaimsArray => {
|
||||||
if(channelClaimsArray.length === 0) {
|
if(channelClaimsArray.length === 0) {
|
||||||
|
@ -1062,7 +1073,7 @@ if (!database || !username || !password) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set sequelize options
|
// set sequelize options
|
||||||
const sequelize$1 = new Sequelize(database, username, password, {
|
const sequelize = new Sequelize(database, username, password, {
|
||||||
host : host$1,
|
host : host$1,
|
||||||
import : port,
|
import : port,
|
||||||
dialect : 'mysql',
|
dialect : 'mysql',
|
||||||
|
@ -1086,8 +1097,8 @@ for(let i = 0; i < DATABASE_STRUCTURE_KEYS.length; i++) {
|
||||||
let dbKey = DATABASE_STRUCTURE_KEYS[i];
|
let dbKey = DATABASE_STRUCTURE_KEYS[i];
|
||||||
let currentData = DATABASE_STRUCTURE[dbKey];
|
let currentData = DATABASE_STRUCTURE[dbKey];
|
||||||
|
|
||||||
db[dbKey] = currentData.table.createModel(sequelize$1, Sequelize);
|
db[dbKey] = currentData.table.createModel(sequelize, Sequelize);
|
||||||
db[dbKey].queries = currentData.queries(db, db[dbKey]);
|
db[dbKey].queries = currentData.queries(db, db[dbKey], sequelize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// run model.association for each model in the db object that has an association
|
// run model.association for each model in the db object that has an association
|
||||||
|
@ -1100,7 +1111,7 @@ DATABASE_STRUCTURE_KEYS.forEach(modelName => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// establish mysql connection
|
// establish mysql connection
|
||||||
sequelize$1
|
sequelize
|
||||||
.authenticate()
|
.authenticate()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
logger$2.info('Sequelize has established mysql connection for chainquery successfully.');
|
logger$2.info('Sequelize has established mysql connection for chainquery successfully.');
|
||||||
|
|
|
@ -7,7 +7,8 @@ const getChannelClaims = async (channelName, channelShortId, page) => {
|
||||||
const channelId = await chainquery.claim.queries.getLongClaimId(channelName, channelShortId);
|
const channelId = await chainquery.claim.queries.getLongClaimId(channelName, channelShortId);
|
||||||
const channelClaims = await chainquery.claim.queries.getAllChannelClaims(channelId);
|
const channelClaims = await chainquery.claim.queries.getAllChannelClaims(channelId);
|
||||||
|
|
||||||
const processedChannelClaims = await channelClaims.map((claim) => getClaimData(claim));
|
const processingChannelClaims = channelClaims ? channelClaims.map((claim) => getClaimData(claim)) : [];
|
||||||
|
const processedChannelClaims = await Promise.all(processingChannelClaims);
|
||||||
|
|
||||||
return returnPaginatedChannelClaims(channelName, channelId, processedChannelClaims, page);
|
return returnPaginatedChannelClaims(channelName, channelId, processedChannelClaims, page);
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@ const chainquery = require('chainquery');
|
||||||
|
|
||||||
const claimShortId = async ({ ip, originalUrl, body, params }, res) => {
|
const claimShortId = async ({ ip, originalUrl, body, params }, res) => {
|
||||||
try {
|
try {
|
||||||
let shortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(params.longId, params.name);
|
let shortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(params.longId, params.name).catch(() => {});
|
||||||
|
|
||||||
if(shortId === null) {
|
if(shortId === null) {
|
||||||
shortId = await db.Claim.getShortClaimIdFromLongClaimId(params.longId, params.name);
|
shortId = await db.Claim.getShortClaimIdFromLongClaimId(params.longId, params.name);
|
||||||
|
|
|
@ -25,11 +25,11 @@ const getClaimIdAndServeAsset = (channelName, channelClaimId, claimName, claimId
|
||||||
})
|
})
|
||||||
.then(claim => {
|
.then(claim => {
|
||||||
if (!claim) {
|
if (!claim) {
|
||||||
logger.debug('Full claim id:', fullClaimId);
|
logger.debug('Full claim id:', claimId);
|
||||||
return db.Claim.findOne({
|
return db.Claim.findOne({
|
||||||
where: {
|
where: {
|
||||||
name : claimName,
|
name : claimName,
|
||||||
claimId: fullClaimId,
|
claimId,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ const getClaimId = async (channelName, channelClaimId, name, claimId) => {
|
||||||
} else {
|
} else {
|
||||||
let claimIdResult = await chainquery.claim.queries.getLongClaimId(name, claimId);
|
let claimIdResult = await chainquery.claim.queries.getLongClaimId(name, claimId);
|
||||||
|
|
||||||
if(claimIdResult === null) {
|
if(!claimIdResult) {
|
||||||
claimIdResult = await db.Claim.getLongClaimId(name, claimId);
|
claimIdResult = await db.Claim.getLongClaimId(name, claimId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,8 +75,11 @@ module.exports = function (req, res) {
|
||||||
res.claimId = showState.assetList[assetKeys[0]].claimId;
|
res.claimId = showState.assetList[assetKeys[0]].claimId;
|
||||||
} else {
|
} else {
|
||||||
var channelKeys = Object.keys(showState.channelList);
|
var channelKeys = Object.keys(showState.channelList);
|
||||||
|
|
||||||
|
if (channelKeys.length !== 0) {
|
||||||
res.claimId = showState.channelList[channelKeys[0]].longId;
|
res.claimId = showState.channelList[channelKeys[0]].longId;
|
||||||
res.isChannel = true;
|
res.isChannel = true;
|
||||||
|
}
|
||||||
} // render component to a string
|
} // render component to a string
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,12 @@ module.exports = (req, res) => {
|
||||||
res.claimId = showState.assetList[assetKeys[0]].claimId;
|
res.claimId = showState.assetList[assetKeys[0]].claimId;
|
||||||
} else {
|
} else {
|
||||||
const channelKeys = Object.keys(showState.channelList);
|
const channelKeys = Object.keys(showState.channelList);
|
||||||
|
|
||||||
|
if(channelKeys.length !== 0) {
|
||||||
res.claimId = showState.channelList[channelKeys[0]].longId;
|
res.claimId = showState.channelList[channelKeys[0]].longId;
|
||||||
res.isChannel = true;
|
res.isChannel = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// render component to a string
|
// render component to a string
|
||||||
const html = renderToString(
|
const html = renderToString(
|
||||||
|
|
Loading…
Reference in a new issue