Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Local Datastore chapter, fromPin and fromlocaldatastore

Just like as title, I want to ask what difference between

fromPin()

and

fromLocalDatastore()

By the way, Pin and datastore two terminologies. What difference between two of them ?

Thanks.

like image 772
user1190887 Avatar asked Aug 28 '14 13:08

user1190887


1 Answers

There is a slight difference and you can see it from the docs and from the decompiled code of the Parse library (okay, this last one is more complicated...).

The docs says:

fromLocalDatastore(): Change the source of this query to all pinned objects.

fromPin(): Change the source of this query to the default group of pinned objects.

Here you can see that, interally on Parse, there is a way to get all the objects from the entire set of pinned data, without filters, but also from a so-called "default group". This group is defined in the Parse code with the following string: _default (o'rly?).

When you pin something using pinInBackground, you can do it in different ways:

pinInBackground() [without arguments]: Stores the object and every object it points to in the local datastore.

This is what the docs say, but if you look at the code you'll discover that the pin will be actually performed to the... _default group!

public Task<Void> pinInBackground() {
    return pinAllInBackground("_default", Arrays.asList(new ParseObject[] { this }));
}

On the other hand, you can always call pinInBackground(String group) to specify a precise group.

Conclusion: every time you pin an object, it's guaranteed to be pinned to a certain group. The group is "_default" if you don't specify anything in the parameters. If you pin an object to your custom group "G", then a query using fromPin() will not find it! Because you didn't put it on "_default", but "G".

Instead, using fromLocalDatastore(), the query is guaranteed to find your object because it will search into "_default", "G" and so on.

like image 179
TheUnexpected Avatar answered Sep 22 '22 19:09

TheUnexpected