parse-community / Parse-SDK-iOS-OSX

The Apple SDK for Parse Platform (iOS, macOS, watchOS, tvOS)
https://parseplatform.org
Other
2.81k stars 871 forks source link

Fetching pinned objects issues (2) #77

Closed acegreen closed 9 years ago

acegreen commented 9 years ago

This maybe my specific implementation but I have a scenario where I would like to saveEventually and still pin the object, regardless of the outcome of the saveEventually.

This matters to me because I can then manipulate the object locally without fetching it again, then saveEventually again when I'm done.

saveEventually can pin the object or do whatever but if I purposely pin an object using the pinInBackgroundWithBlock I expect it to stay pinned regardless.

nlutsenko commented 9 years ago

Hey @acegreen, sorry it took a while to get back to you on this one. You can still pin any object to Local Datastore, regardless of whether you are saving it eventually or not. And it will still stay pinned, regardless if saveEventually succeeds or fails.

Since PFObject is guaranteed to be a single instance in-memory if you have Local Datastore enabled - all the changes that you make to this object, or anything that updates that object (like querying for it) - will propagate to the object and will be available to you.

acegreen commented 9 years ago

@nlutsenko Thanks for getting back to me on this, i have been struggling to get localDataStore working for a while now. What you said above is exactly what I was hoping for but something doesn't seem right

Here is what I'm doing to saveEventually and pin my object

        currentObject.pinInBackgroundWithBlock({ (success, error) -> Void in

            if success {

                print("pinned successfully")
            }

        })

        currentObject.saveEventually()

Then to retrieve my objects i do:

    var parseLocalQuery = PFQuery(className:"Stocks")
    parseLocalQuery.fromLocalDatastore()
    parseLocalQuery.whereKey("Symbol", containedIn: symbolStringArray)
    parseLocalQuery.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in

        if error == nil {

            if let objects = objects as? [PFObject] {

                // The find succeeded.
                print("Successfully retrieved \(objects.count) object")

            }

        } else {

            // Log details of the failure
            print("Error: \(error) \(error!.userInfo)")

        }
    })

if i comment out .fromLocalDatastore() it retrieves the object. But with it, the query comes back empty (count = 0).

Notes:

nlutsenko commented 9 years ago

tried to remove saveEventually() completely and just leave pinInBackgroundWithBlock and still no results

If this code doesn't work even without saveEventually() - it's quite possible that saveEventually() piece is completely unrelated to this. Is it possible that there is no object Stocks that have Symbol inside symbolStringArray in Local Datastore?

acegreen commented 9 years ago

I only tried to remove saveEventually() after posting this. Might not be but I thought saveEventually() only pins until it can save then removes the object from localDatastore.

i tried to remove the .whereKey predicate but still empty. I did notice though that VERY rarely it actually retrieves something. can be that it requires a REALLY long time to pin? Even though, it shows pin successful right after i pin it?

acegreen commented 9 years ago

The object should have Symbol inside it as it is the same object I fetched from the cloud easier.

Here is the workflow:

  1. Fetch objects from data
  2. When button is pressed, pin object
  3. when deleting object, fetch object fromLocalDatastore
  4. do something to object and delete it

The struggle is with step 3. If I do step 3 from the cloud using the whereKey of symbolStringArray it works. Doing it from local WITH or WITHOUT whereKey, query is empty

nlutsenko commented 9 years ago

This sounds very strange. Do you have query fetching being done after the pinning happened?

A repro project or code snippet would be the best help here, since the code above is quite generic.

acegreen commented 9 years ago

@nlutsenko apologize for the delayed reply, didn't have access to my computer.

The query is DEFINITELY being executed after the pin.

Sample code is above, but I'll need to figure out who to setup a repro project because the project is a little sensitive. Can we setup a short chat outside to show you the issue first hand

Raesu commented 9 years ago

I would like to hear any conclusions from this topic. I have noticed some unusual behavior when pinning and using saveEventually.

acegreen commented 9 years ago

@nlutsenko i would like to address this as well. A short skype session would be very efficient to show you what I'm talking about

nlutsenko commented 9 years ago

Hey @acegreen, sorry - got tangled in other things. Can you share the piece of code that you use for pinning the object, the object schema and query here?

This sounds like a general use case of Local Datastore (pin an object, query for it), as we previously discussed looks like not related to saveEventually.

Feel free to share the project with me privately (nlutsenko@fb.com) or in any way you want to.

parse-github-bot commented 9 years ago

Thank you for your feedback. We prioritize issues that have clear and concise repro steps. Please see our Bug Reporting Guidelines about what information should be added to this issue.

Please try the latest SDK. Our release notes have details about what issues were fixed in each release.

In addition, you might find the following resources helpful:

acegreen commented 9 years ago

@nlutsenko Its hard to show you my specific case using a demo or snippet code. I would just schedule a 5 minute session to show you the code in action. If it turns out to be an actual problem, we will document it here for everyone to follow

nlutsenko commented 9 years ago

@acegreen, the best way to help you would be to look at the sample project that reproduces the issue, or a snippet of code that includes information I referenced above. If you explicitly need to share it privately, feel free to reach out via email or Facebook Messenger.

parse-github-bot commented 9 years ago

This issue has not been updated for 7 days. If you have additional information to help pinpoint this issue as an SDK bug, please comment on this issue. We will close this issue in 7 days if no additional information is provided. Thank you for your feedback.

parse-github-bot commented 9 years ago

We are closing this issue due to another 7 days of inactivity. If you have additional information to help pinpoint this issue as an SDK bug, please reopen it with the additional information.Thank you for your feedback.

acegreen commented 8 years ago

@nlutsenko

So I'm taking another jab at this issue. Suddenly with 1.10.0, fetching from fromLocalDatastore returns stuff. Literally the exact same code. If you remember the fetching was always empty from fromLocalDatastore. So we are one step closer!!!

But then I try to do:

    parseLocalQuery.findObjectsInBackgroundWithBlock({ (objects, error) -> Void in
        if error == nil {
            if let objects = objects {
                // The find succeeded.
                print("Successfully retrieved \(objects.count) object")
                for object in objects {
                    object.removeObject(PFUser.currentUser()!, forKey: "Shorted_By")
                    object.removeObject(PFUser.currentUser()!, forKey: "Longed_By")

                    object.saveEventually()

                    print("User removed from object: \(object)")
                }

And it just doesn't go further, no crash but the rest of my code doesn't run further. Also the currentUser is not removed from those objects online.

All I need was add fromLocalDatastore, so the code works as expected when I remove that. Here's proof that the same code work without fromLocalDatastore:

screen shot 2015-12-24 at 12 02 55 pm
acegreen commented 8 years ago

Just two notes:

  1. Issue still there on 1.11.0
  2. If I comment out the removeObject lines, the code executes as expected. but that means I can't remove stuff from a pinned object? // object.removeObject(PFUser.currentUser()!, forKey: "Shorted_By") // object.removeObject(PFUser.currentUser()!, forKey: "Longed_By")
acegreen commented 8 years ago

@nlutsenko see notes above, if I try to do the above with fromLocalDatastore() it just jumps the rest of my code. If I comment these removeObject out, it runs.

I pinned the objects to my local datastore so I can later retrieve them and manipulate them and do saveEventually.

gstream commented 7 years ago

I am facing same issue. After pinned object, I can't retrieve from local database. [[query findObjectsInBackground] continueWithBlock:^id(BFTask *task) { if (task.error) { NSLog(@"Error: %@", task.error); return task; }

        NSLog(@"Retrieved %@", task.result);
        return task;
    }]

Fetching object from local database always returns 0 elements array.

gstream commented 7 years ago

But can retrieve objects without this line. [query fromLocalDatastore];