From 05b7a4eb62d4da705847c397c2a053796a9c9912 Mon Sep 17 00:00:00 2001 From: jessop Date: Wed, 19 Dec 2018 02:16:36 -0500 Subject: [PATCH] reduces channel loadtimes, fixes fallback fileExt --- .../api/channel/claims/getChannelClaims.js | 2 +- server/utils/getClaimData.js | 33 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/server/controllers/api/channel/claims/getChannelClaims.js b/server/controllers/api/channel/claims/getChannelClaims.js index 0c7f142e..773c2ba8 100644 --- a/server/controllers/api/channel/claims/getChannelClaims.js +++ b/server/controllers/api/channel/claims/getChannelClaims.js @@ -23,7 +23,7 @@ const getChannelClaims = async (channelName, channelShortId, page) => { ); channelClaims = split.zero.concat(split.nonzero); - const processingChannelClaims = channelClaims ? channelClaims.map((claim) => getClaimData(claim)) : []; + const processingChannelClaims = channelClaims ? channelClaims.map((claim) => getClaimData(claim, channelName, channelShortId)) : []; const processedChannelClaims = await Promise.all(processingChannelClaims); return returnPaginatedChannelClaims(channelName, channelId, processedChannelClaims, page); diff --git a/server/utils/getClaimData.js b/server/utils/getClaimData.js index 2e270d20..b898d683 100644 --- a/server/utils/getClaimData.js +++ b/server/utils/getClaimData.js @@ -2,30 +2,31 @@ const { details: { host } } = require('@config/siteConfig'); const chainquery = require('chainquery').default; const { getClaim } = require('server/lbrynet'); -module.exports = async (data) => { +module.exports = async (data, chName = null, chShortId = null) => { // TODO: Refactor getching the channel name out; requires invasive changes. const certificateId = data.publisher_id || data.certificateId; - const lbrynetUri = `${data.name}#${data.claim_id}`; - let channelName = data.channelName; + let lbrynetClaimResult = null; + let lbrynetFileExt = null; + let channelShortId = chShortId; + let channelName = chName; - if (certificateId && !channelName) { - channelName = await chainquery.claim.queries.getClaimChannelName(certificateId).catch(() => {}); + if (!chName && certificateId && !channelName) { + channelName = await chainquery.claim.queries.getClaimChannelName(certificateId).catch(() => { + }); } - let channelShortId = null; - if (certificateId && channelName) { + if (!chShortId && certificateId && channelName) { channelShortId = await chainquery.claim.queries.getShortClaimIdFromLongClaimId(certificateId, channelName).catch(() => null); } - let lbrynetClaimResult = null; - let lbrynetFileExt = null; + if (!chName && !chShortId && !data.fileExt) { + const lbrynetUri = `${data.name}#${data.claim_id}`; + lbrynetClaimResult = await getClaim(lbrynetUri).catch(() => { + return 'invalid URI'; + }); + lbrynetFileExt = lbrynetClaimResult && lbrynetClaimResult.file_name && lbrynetClaimResult.file_name.includes('.') && lbrynetClaimResult.file_name.split('.').slice(-1).pop(); + } - // if (!data.fileExt) { - // lbrynetClaimResult = await getClaim(lbrynetUri).catch(() => { return 'invalid URI' }); - // lbrynetFileExt = lbrynetClaimResult && lbrynetClaimResult.file_name && lbrynetClaimResult.file_name.split('.').slice(-1).pop(); - // } - - // TODO verify that "generated_x" does anything at all return ({ name : data.name, title : data.title, @@ -37,7 +38,7 @@ module.exports = async (data) => { fileExt : data.generated_extension || data.fileExt || lbrynetFileExt, description: data.description, thumbnail : data.generated_thumbnail || data.thumbnail_url || data.thumbnail, - outpoint : data.transaction_hash_id || data.outpoint, + outpoint : `${data.transaction_hash_id}:${data.vout}` || data.outpoint, host, pending : Boolean(data.height === 0), });