Steem Dev Series #5 - How steemit uses steemjs for getDiscussions
So, I couldn't decide how helpful this would be but since there are always so many questions I thought I would make a quick post about this. This is from the condenser(steemit) code where they call steemjs to get the post data in different ways. Basically just need to use what they are using for args as your query.
if (order === 'trending') {
call_name = 'getDiscussionsByTrendingAsync';
args = [
{ tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if (order === 'trending30') {
call_name = 'getDiscussionsByTrending30Async';
args = [
{ tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if (order === 'promoted') {
call_name = 'getDiscussionsByPromotedAsync';
args = [
{ tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if( order === 'active' ) {
call_name = 'getDiscussionsByActiveAsync';
args = [
{ tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if( order === 'cashout' ) {
call_name = 'getDiscussionsByCashoutAsync';
args = [
{ tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if( order === 'payout' ) {
call_name = 'getPostDiscussionsByPayout';
args = [
{ tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if( order === 'payout_comments' ) {
call_name = 'getCommentDiscussionsByPayout';
args = [
{ tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if( order === 'updated' ) {
call_name = 'getDiscussionsByActiveAsync';
args = [
{ tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if( order === 'created' || order === 'recent' ) {
call_name = 'getDiscussionsByCreatedAsync';
args = [
{ tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if( order === 'by_replies' ) {
call_name = 'getRepliesByLastUpdateAsync';
args = [author, permlink, constants.FETCH_DATA_BATCH_SIZE];
} else if( order === 'responses' ) {
call_name = 'getDiscussionsByChildrenAsync';
args = [
{ tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if( order === 'votes' ) {
call_name = 'getDiscussionsByVotesAsync';
args = [
{ tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if( order === 'hot' ) {
call_name = 'getDiscussionsByHotAsync';
args = [
{ tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if( order === 'by_feed' ) {
call_name = 'getDiscussionsByFeedAsync';
args = [
{ tag: accountname,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if( order === 'by_author' ) {
call_name = 'getDiscussionsByBlogAsync';
args = [
{ tag: accountname,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else if( order === 'by_comments' ) {
call_name = 'getDiscussionsByCommentsAsync';
args = [
{ limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
} else {
call_name = 'getDiscussionsByActiveAsync';
args = [{
tag: category,
limit: constants.FETCH_DATA_BATCH_SIZE,
start_author: author,
start_permlink: permlink}];
}
I also saw a question from someone on how to grab multiple tags. If you are going to be running your own front-end you should consider using a database to store the posts and create a lookup for the tags. Alternatively if you are just using steemjs make one call for each tag and then combine the two into a set using the author and permlink as a key to dedupe your data. Lodash has some methods that would be very useful for this.
Thanks for sharing! Is there a way to query posts by time elapsed? I'd like to get posts starting from 15 minutes old and can't figure out how to do it except load a big amount of posts and then filter them out.
You are going to have to find a post that is fifteen minutes old and then use it as the start author and start permlink. The fastest way to do this would be to load a bunch of posts and then do a binary search although the easiest is going to be to load a bunch and just iterate through them looking for the first one that is 15 minutes old. Your list of posts you are looking through is going to be a relatively small set so no real performance hit from just traversing the array in order. I would suggest using the truncate_body argument and set to one since your first call is only to find your start post you don't really need the body for that.
Thank you for the detailed reply, will try this approach. A query date parameter would be very helpful and it's strange that it's missing — I can't imagine how one could get year old posts otherwise.
I am assuming it is just to make the point but if you really wanted posts that old you would probably want to set up your own database at that point that contained the metadata for all posts.
Thanks, good to know!
Congratulations! This post has been upvoted from the communal account, @minnowsupport, by Voorash from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, someguy123, neoxian, followbtcnews/crimsonclad, and netuoso. The goal is to help Steemit grow by supporting Minnows and creating a social network. Please find us in the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.
This post has received a 1.04 % upvote from @drotto thanks to: @banjo.
Thank you for sharing.