Hi,
I have been experiencing inconsistency in data retrieval. The code bellow extracts people whom a particular user is following from the Follows table and the extracts their ID’s which will be used to extract their Posts from Timeline table.
function show(data) {
var content = '<h3>'+data.fullName+' <small style="float:right">'+timesAgoShort(data.createdAt)+'</small></h3>';
content += '<p>'+data.content+' <em style="font-size:10px;">id :'+data.id+'<em></p>';
$('body').append(content);
}
var getFollows = Backendless.Persistence.of( Follows );
var getTimeline = Backendless.Persistence.of( Timeline );
// Get All the people 'D6F3FFF9-A1AF-21F5-FF01-10883E85C500' is following
var promise = new Promise(function(resolve, reject) {
var query = new Backendless.DataQuery();
query.options = {relationsDepth:1, sortBy: "created"};
query.condition= "fromUser.objectId = 'D6F3FFF9-A1AF-21F5-FF01-10883E85C500'";
var result = getFollows.find(query);
var followingUsers = [];
for (var i = 0; i < result.data.length; i++) {
if(result.data.toUser.objectId) {
//Store the users being followed
followingUsers.push({id : result.data.toUser.objectId, fullName : result.data.toUser.name});
}
}
if (followingUsers.length) {
resolve(followingUsers);
}
else {
reject(Error("It broke"));
}
});
// Get All Posts of people, 'D6F3FFF9-A1AF-21F5-FF01-10883E85C500' is following
promise.then(function(followingUsers) {
var query = new Backendless.DataQuery();
var string = '';
for (var i = 0; i < followingUsers.length; i++) {
string += "fromUser.objectId = '"+followingUsers.id+"'";
if((followingUsers.length - 1) > i)
string += ' or ';
}
query.options = {relationsDepth:1, sortBy: "created desc"};
query.condition= string;
var timelineResults= getTimeline.find(query);
for (var i = 0; i < timelineResults.data.length; i++) {
//Display the data in html format
show({id : timelineResults.data.fromUser.objectId, fullName : timelineResults.data.fromUser.name, content : timelineResults.data.content, createdAt : timelineResults.data.created });
}
}, function(err) {
console.log(err);
});
I run this code 3 out of 10 time i get the correct response. I am attaching screenshots
C:\Users\Admin\Downloads\Backendless-Screenshot-(Correct Data).png</img>