updated getRecentClaims

This commit is contained in:
bill bittner 2017-10-31 17:19:26 -07:00
parent b95f7ad5d4
commit 4d23fbbe4e
6 changed files with 13 additions and 12 deletions

View file

@ -64,7 +64,7 @@ function getAssetByLongClaimId (fullClaimId, name) {
}
logger.debug('no local file found for this name and claimId');
// 2. if no local claim, resolve and get the claim
db
db.Claim
.resolveClaim(name, fullClaimId)
.then(resolveResult => {
logger.debug('resolve result >> ', resolveResult);
@ -130,7 +130,7 @@ module.exports = {
getAssetByChannel (channelName, channelId, claimName) {
logger.debug('getting asset by channel');
return new Promise((resolve, reject) => {
db.getLongChannelId(channelName, channelId) // 1. get the long channel id
db.Certificate.getLongChannelId(channelName, channelId) // 1. get the long channel id
.then(result => { // 2. get the long claim Id
if (result === NO_CHANNEL) {
resolve(NO_CHANNEL);
@ -155,7 +155,7 @@ module.exports = {
return new Promise((resolve, reject) => {
let longChannelId;
let shortChannelId;
db.getLongChannelId(channelName, channelId) // 1. get the long channel Id
db.Certificate.getLongChannelId(channelName, channelId) // 1. get the long channel Id
.then(result => { // 2. get all claims for that channel
if (result === NO_CHANNEL) {
return NO_CHANNEL;
@ -220,7 +220,7 @@ module.exports = {
.getShortClaimIdFromLongClaimId(fileInfo.claimId, fileInfo.name)
.then(shortId => {
fileInfo['shortId'] = shortId;
return db.resolveClaim(fileInfo.name, fileInfo.claimId);
return db.Claim.resolveClaim(fileInfo.name, fileInfo.claimId);
})
.then(resolveResult => {
logger.debug('resolve result >>', resolveResult);

View file

@ -97,7 +97,7 @@ module.exports = {
logger.debug('retrieving most recent claims');
return new Promise((resolve, reject) => {
// get the raw requests data
db.getRecentClaims()
db.File.getRecentClaims()
.then(results => {
resolve(results);
})

View file

@ -146,7 +146,6 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
});
};
// sequelize.query(`SELECT claimId, height FROM Certificate WHERE name = '${channelName}' AND claimId LIKE '${channelId}%' ORDER BY height ASC LIMIT 1;`, { type: db.sequelize.QueryTypes.SELECT })
Certificate.getLongChannelIdFromShortChannelId = function (channelName, channelId) {
return new Promise((resolve, reject) => {
this
@ -173,7 +172,6 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
});
};
// sequelize.query(`SELECT claimId, amount, height FROM Certificate WHERE name = '${channelName}' ORDER BY effectiveAmount DESC, height ASC LIMIT 1;`, { type: db.sequelize.QueryTypes.SELECT })
Certificate.getLongChannelIdFromChannelName = function (channelName) {
logger.debug(`getLongChannelIdFromChannelName(${channelName})`);
return new Promise((resolve, reject) => {

View file

@ -309,7 +309,6 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, ARRAY, DECIMAL, D
}
};
// sequelize.query(`SELECT name, claimId, outpoint, height, address, title, description, thumbnail, certificateId, channelName FROM Claim WHERE name = '${name}' AND claimId = '${claimId}'`, { type: db.sequelize.QueryTypes.SELECT })
Claim.resolveClaim = function (name, claimId) {
return new Promise((resolve, reject) => {
this

View file

@ -55,5 +55,13 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER }) => {
File.hasOne(db.Claim);
};
File.getRecentClaims = function () {
return this.findAll({
where: { nsfw: false, trendingEligible: true },
order: [['createdAt', 'DESC']],
limit: 25,
});
};
return File;
};

View file

@ -74,8 +74,4 @@ db.getTrendingClaims = (startDate) => {
return db.sequelize.query(`SELECT COUNT(*), File.* FROM Request LEFT JOIN File ON Request.FileId = File.id WHERE FileId IS NOT NULL AND nsfw != 1 AND trendingEligible = 1 AND Request.createdAt > "${startDate}" GROUP BY FileId ORDER BY COUNT(*) DESC LIMIT 25;`, { type: db.sequelize.QueryTypes.SELECT });
};
db.getRecentClaims = () => {
return db.sequelize.query(`SELECT * FROM File WHERE nsfw != 1 AND trendingEligible = 1 ORDER BY createdAt DESC LIMIT 25;`, { type: db.sequelize.QueryTypes.SELECT });
};
module.exports = db;