fatuhoku
fatuhoku

Reputation: 4911

Do objects pinned in Parse Local datastore get deleted as well when it's deleted on the backend?

Suppose that there are two iDevices: device1 and device2. Both devices have pinned some object foobar retrieved from the Parse backend.

device1 performs a -deleteEventually on foobar. This causes the object to also be automatically unpinned. This deletion is propagated to the backend, and the backend now has removed foobar.

device2 performs a query that would normally fetch foobar; except, it's missing.

What happens to foobar on device2's local datastore?

Upvotes: 3

Views: 4018

Answers (2)

Nastya Gorban
Nastya Gorban

Reputation: 1241

Here is solution for this type of issue that I'm using in my app:

  1. using PFQuery fetch objects from parse
  2. make query local and fetch objects from local storage
  3. unpin objects if they was found in local storage
  4. pin objects that came from network

And code sample:

- (BFTask *)find:(PFQuery *)query {
    return [[query findObjectsInBackground] continueWithSuccessBlock:^id(BFTask *task) {
        BFTask *(^pin)(void) = ^ {
            return [[PFObject pinAllInBackground:task.result] continueWithExecutor:[BFExecutor mainThreadExecutor]
                                                                  withSuccessBlock:^id(BFTask *task) {
                                                                      return task.result;
                                                                  }];
        };

        [query fromLocalDatastore];
        return [[query findObjectsInBackground] continueWithBlock:^id(BFTask *task) {
            if (!task.error && [task.result count]) {
                return [[PFObject unpinAllInBackground:task.result] continueWithBlock:^id(BFTask *task) {
                    return pin();
                }];
            } else {
                return pin();
            }
        }];
    }];
}

Upvotes: 1

Cris R
Cris R

Reputation: 1388

As local datastore is...local, then the object will be keeped in the second device until it receives an update about the objects, and pinned those again (after unpin obviously). No changes will be made in the second one if you are not requesting new objects from the Backend.

Upvotes: 3

Related Questions