Parse local datastore query takes time on Android - android

I have pinned object for first time. Next time i try to fetch same object it takes time sometimes like 5 to 6 second in this the screen turns blank.
Here is my code for pinning. (Both pinning and querying data from local store is done on same table in parse)
ParseQuery<ParseObject> query = ParseQuery.getQuery(PARSE_IMAGE_TABLE);
List<ParseObject> images = query.find();
for each image i get i do following:
parseObject.pinInBackground(PARSE_PIN_WALLPAPER_INFO,
new SaveCallback() {
#Override
public void done(ParseException arg0) {
System.out.println();
}
});
When querying:
ParseQuery<ParseObject> query = ParseQuery.getQuery(PARSE_IMAGE_TABLE);
query.whereEqualTo(PARSE_IMAGE_THUMB_URL, imageURL);
query.fromLocalDatastore();
query.fromPin();
List<ParseObject> images = query.find(); -- this call takes time

Yes their is a lot of performance tweaks you can do in your code.
Pinning a list of objects is faster and better approach.
Instead of using find query use findInBackground.
Also start using pin(String name) and fromPin(String name) instead of fromPin() and fromPin(String name). This has a huge advantage if you have a lot of rows in your parse local storage.

Related

How to populate recyclerview with data from parse server?

Is it possible to retrieve all the data present in a specific class in the parse server in the form of a news feed similar to facebook using recyclerView?
in order to do it you need to do the following:
I recommend you to use Parse SDK for android. You can read the docs in here . This SDK will make your life easy with performing all CRUD operations in front of your parse server instance. So the thing that you need to do is to execute query on your class like the following (taken from parse server docs):
ParseQuery<ParseObject> query = ParseQuery.getQuery("<YOUR_CLASS_NAME>");
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> scoreList, ParseException e) {
if (e == null) {
Log.d("score", "Retrieved " + scoreList.size() + " scores");
} else {
Log.d("score", "Error: " + e.getMessage());
}
}
});
From the code above you can see that we first create a query object on class and then use findInBackground in order to retrieve all objects.
Inside that findInBackground callback what you need to do is to iterate on all results and map them to your recyclerView adapter and finally refresh it and see the results
From the answer above you can see that's its pretty simple task if you use Parse Android SDK. As much as I know there is no out of the box solution that will create recyclerView from parse query results.

Complex Parse Query in Android

I have these Classes in parse db.
User ...
Post (user pointer<_User> | images Relation )
Image (post pointer | image File )
Follow ( user_from pointer | user_to pointer)
The questions are,
1- How to get the list of posts with their images of users who i am following. (in java android)
2- How to get a list of my posts.
3- How o get a list of my followers.
4- example of java class of User, Post, Image and Follow objects.
thanks
probably you'll need to construct a relational queries, like the example below:
ParseQuery<ParseObject> innerQuery = ParseQuery.getQuery("Post");
innerQuery.whereExists("image");
ParseQuery<ParseObject> query = ParseQuery.getQuery("_User");
query.whereEqualTo("postPointer", innerQuery);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> commentList, ParseException e) {
// comments now contains the comments for posts without images.
}
});
You can check more about it at Parse Docs

Android parse.com setObjectId

How set objectId with Parse.com with primary key.Can you help me ?
When i create new row, i want setObjectId of row.
final ParseObject parseObject = new ParseObject(ChapsModel.PARSE_OBJECT);
parseObject.put(ChapsModel.PARSE_FIELD_NAME_CHAPS,
chapsModel.get(i)
.getNamChap());
parseObject.put(ChapsModel.PARSE_FIELD_LINK_CHAP,
chapsModel.get(i)
.getLinkChap());
parseObject.put(ChapsModel.PARSE_FILED_TEAM_TRANSLATE,
chapsModel.get(i)
.getTeamTranslate());
parseObject.put(ChapsModel.PARSE_FIELD_OBJECT_MANGA,
ParseObject.createWithoutData(MangaModel.PARSE_OBJECT,
chapsModel.get(i)
.getObjectManga()));
parseObject.saveInBackground(new SaveCallback() {
#Override
public void done(final ParseException e) {
if (e == null) {
Log.e(">>>>>",
"done" + ojectId);
// parseObject.setObjectId(ojectId);
} else {
Log.e(">>>>>",
"else" + e.getMessage());
}
}
});
Log
java.lang.RuntimeException: objectIds cannot be changed in offline mode.
Log:
Sorry my english. thank
It's not possible to set objectId with Parse.com with primary key.
Although parse.com doesn't allow us to set the objectId of a row, you can create a new column named anything you want and you can set that new column to any objectId you want. For example, you can create a new column named myObjectId and set it to a string.
From the parse.com website at https://www.parse.com/docs/js/guide#cloud_code
The Data Browser
The Data Browser is the web UI where you can update and create objects in each of your apps. Here, you can see the raw JSON values that are saved that represents each object in your class.
When using the interface, keep in mind the following:
The objectId, createdAt, updatedAt fields cannot be edited (these are set automatically).

Find all following users where their username begins with myString

These are the columns of my Follow Table:
user (Pointer _User)
follower (Pointer _User)
What I want to do is to get all the user where
follower = currentUser
user.username begins with a certain string
I know that in lower-lever db (like mySQL) these data can all be fetched with a single query.
Is it possible in parse? If not, what's the best way to do such a thing?
Assuming your currentUser object is a PFUser
Note... I am program with parse in objective-c so I am not 100% sure this will run. But I feel like this is what your looking for... Your going to have to first query for all the followers who's follower field is equal to the current user.
Then join that query with a user query whose usernames or names, whatever, are equal to your string you pass in... beware the string you pass into the query is case-sensitive... i think...
So if a user in your app searches for BOB and the database has Bob stored... the query won't return Bob... It will just return nothing....
ParseQuery<ParseUser> userQuery = ParseUser.getQuery();
userQuery.whereEqualTo("username", certainString);
ParseQuery<ParseObject> followerQuery = ParseQuery.getQuery("Followers");
followerQuery.whereEqualTo("follower", ParseUser.getCurrentUser());
followerQuery.matchesKeyInQuery("user", "follower", userQuery);
userQuery.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> list, ParseException e) {
// comments now contains the comments for posts with images.
}
});
EDIT Going through Parse's Anypic project that does what you want... I feel that this is not possible... Your going to have to first make a query for the users in the followers table whose followers key is the current user. Then find the objects. Once the result is returned, iterate through the objects to whose names is contained within the contains string.
ParseQuery<ParseObject> followerQuery = ParseQuery.getQuery("Followers");
followerQuery.whereEqualTo("username", certainString);
followerQuery.whereNotEqualTo("username", ParseUser.getCurrentUser().username);
followerQuery.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> list, ParseException e) {
for (ParseObject element : list) {
if (element.user == ParseUser.getCurrentUser()) {
//This is a follower of the current user... append to a list object or whatever
}
}
// update a label or table once the iteration is done.
}
});
There still may be a solid solution for what you want to do in one query but I can't think of it right now... Ill come back to this post if I do.

Android | Parse.com | Query User Collection with another Collection

i have basic question. Iam using parse android SDK to retrieve some data from backend. I have 2 collections : "User" and "Photo". What i want to do is that i want to query "Photo" collection which contains some data about image and join that against "User" collection and get some info about owner of picture. Please see code below:
ParseQuery<ParseUser> queryInner = ParseUser.getQuery();
ParseQuery<ParseObject> query = ParseQuery.getQuery("Photo");
query.whereMatchesKeyInQuery("owner", "username", queryInner);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> resultSet, ParseException exception) {
if (exception == null) {
parsqQueryResult = new ArrayList<ObjectUserPhoto>();
ObjectUserPhoto row = new ObjectUserPhoto();
Log.e("size",String.valueOf(resultSet.size()));
for (int a = 0; a < resultSet.size(); a++) {
row = new ObjectUserPhoto();
//this works
row.setDescription(resultSet.get(a).getString(Constants.DB_COL_USER_PHOTOS_DESCRIPTION));
//this is not working
Log.e("username",String.valueOf(resultSet.get(a).getString("col_from_user_table")));
parsqQueryResult.add(row);
}
}
}
});
So basically iam able to acces columns from "Photo" collection, but iam not able to acces any column from "User" collection. How can i acces data from "User" collection ??
Thanks
Martin
In your comment you mentioned that you are not using pointers. I assume that you are just storing the id of the ParseUser objects.
Given a ParseObject's ID, you can retrieve an object by issuing a ParseQuery and passing the ID. Refer to this document.
However, I do not see any reason why you would want to store just the ID and not the Pointer to the object. Imagine if you want to display the information on a list then that means for every item you will need to perform a ParseQuery.
If you store a Pointer then you can leverage on the "include" method (see it here at the bottom part of the "Relational Queries"). This allows you to include the actual object the Pointer is pointing to. So in your case, the results of the Photo query will include the User objects too.
And lastly, I suggest that you read through at least the whole Objects and Queries sections of the documentation as you would learn the basics on how to use the SDK.

Categories

Resources