fixes blank tiles due to unsupported content #755

Merged
jessopb merged 1 commit from pagination into master 2018-11-27 17:22:05 +01:00
3 changed files with 62 additions and 16 deletions
Showing only changes of commit 2227ede6e9 - Show all commits

View file

@ -869,15 +869,35 @@ var claimQueries = (db, table, sequelize) => ({
});
},
getAllChannelClaims: async (channelClaimId, bidState) => {
getAllChannelClaims: async (channelClaimId, params) => {
logger$1.debug(`claim.getAllChannelClaims for ${channelClaimId}`);
const whereClause = bidState || {
[sequelize.Op.or]: [
{ bid_state: 'Controlling' },
{ bid_state: 'Active' },
{ bid_state: 'Accepted' },
],
const defaultWhereClauses = {
bid_state:
{ [sequelize.Op.or]: ['Controlling', 'Active', 'Accepted'] }
};
const addWhereClauses = (whereClauses, params) => {
/*
input params = { col: ['Val', 'Val']}
output = { col: { Op.or : [ { Op.eq: 'Value'},...]}, col2:...}
*/
const cols = Object.keys(params);
for (let colKey in cols){
let col = Object.keys(params)[colKey];
whereClauses[col] = {};
whereClauses[col][sequelize.Op.or] = [];
for (let itemKey in params[col] ){
let itemsArr = params[col];
whereClauses[col][sequelize.Op.or].push({ [sequelize.Op.eq]: itemsArr[itemKey] });
}
}
return whereClauses;
};
const whereClause = addWhereClauses(defaultWhereClauses, params);
const selectWhere = {
...whereClause,
publisher_id: channelClaimId,

View file

@ -68,15 +68,35 @@ export default (db, table, sequelize) => ({
});
},
skhameneh commented 2018-11-21 17:59:43 +01:00 (Migrated from github.com)
Review

This needs to be optional, chainquery functions should not be opinionated on Spee.ch content types.

This needs to be optional, chainquery functions should not be opinionated on Spee.ch content types.
getAllChannelClaims: async (channelClaimId, bidState) => {
getAllChannelClaims: async (channelClaimId, params) => {
logger.debug(`claim.getAllChannelClaims for ${channelClaimId}`);
const whereClause = bidState || {
[sequelize.Op.or]: [
{ bid_state: 'Controlling' },
{ bid_state: 'Active' },
{ bid_state: 'Accepted' },
],
const defaultWhereClauses = {
skhameneh commented 2018-11-26 17:20:51 +01:00 (Migrated from github.com)
Review

See here and the original signature of getAllChannelClaims: async (channelClaimId, bidState), this allows all claims to be fetched. The changes break this pattern and force Spee.ch filtering on code that should be unopinionated.

See here and the original signature of `getAllChannelClaims: async (channelClaimId, bidState)`, this allows all claims to be fetched. The changes break this pattern and force Spee.ch filtering on code that should be unopinionated.
jessopb commented 2018-11-27 05:05:06 +01:00 (Migrated from github.com)
Review

I had read that once you go beyond 1 optional parameter, you're better off passing an object. With bidState already being optional and not passed from the controller, contentTypes would have to be a second optional parameter, meaning the function, I think, would have to be called with ( first, null, third ). Is there a better way to make contentTypes optional? I'm leading toward a GetMatchingChannelClaims function in chainquery instead. This would pave the way for future db queries.

I had read that once you go beyond 1 optional parameter, you're better off passing an object. With bidState already being optional and not passed from the controller, contentTypes would have to be a second optional parameter, meaning the function, I think, would have to be called with ( first, null, third ). Is there a better way to make contentTypes optional? I'm leading toward a GetMatchingChannelClaims function in chainquery instead. This would pave the way for future db queries.
bid_state:
{ [sequelize.Op.or]: ['Controlling', 'Active', 'Accepted'] }
};
const addWhereClauses = (whereClauses, params) => {
/*
input params = { col: ['Val', 'Val']}
output = { col: { Op.or : [ { Op.eq: 'Value'},...]}, col2:...}
*/
const cols = Object.keys(params)
for (let colKey in cols){
let col = Object.keys(params)[colKey]
whereClauses[col] = {}
whereClauses[col][sequelize.Op.or] = []
for (let itemKey in params[col] ){
let itemsArr = params[col]
whereClauses[col][sequelize.Op.or].push({ [sequelize.Op.eq]: itemsArr[itemKey] })
}
}
return whereClauses;
}
const whereClause = addWhereClauses(defaultWhereClauses, params);
const selectWhere = {
...whereClause,
publisher_id: channelClaimId,

View file

@ -5,10 +5,16 @@ const { returnPaginatedChannelClaims } = require('./channelPagination.js');
const getChannelClaims = async (channelName, channelShortId, page) => {
const channelId = await chainquery.claim.queries.getLongClaimId(channelName, channelShortId);
const params = { content_type: [
'image/jpeg',
'image/jpg',
'image/png',
'image/gif',
'video/mp4',
] };
let channelClaims;
if (channelId) {
channelClaims = await chainquery.claim.queries.getAllChannelClaims(channelId);
channelClaims = await chainquery.claim.queries.getAllChannelClaims(channelId, params);
}
const processingChannelClaims = channelClaims ? channelClaims.map((claim) => getClaimData(claim)) : [];