Skip to content

Ability to revert all changes or a single field on PFObject. #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nlutsenko opened this issue Aug 19, 2015 · 11 comments
Closed

Ability to revert all changes or a single field on PFObject. #52

nlutsenko opened this issue Aug 19, 2015 · 11 comments
Assignees
Milestone

Comments

@nlutsenko
Copy link
Contributor

After changing a single field on PFObject - there is no functionality to revert it back to the server state, even though we have the server state available internally. This is implemented in dotNet SDK via ParseObject.revert() method which reverts any changes to an object that were done after last successful save/fetch.

Implementation would require:

  • Add PFObject.revert() that would clear all operations in operationSetQueue and rebuild estimatedData
  • Add PFObject.revertObjectForKey(key: String) that would remove all operations for that key in operationSetQueue as well as rebuild estimatedData.
@mykrr
Copy link

mykrr commented Aug 19, 2015

I am also facing the same issue as in #51. Please provide us quick fix for this.

@kashif
Copy link
Contributor

kashif commented Aug 19, 2015

so something like:

- (void)revert {
    @synchronized (lock) {
        [operationSetQueue removeAllObjects];
        [self rebuildEstimatedData];
    }
}

-(void)revertObjectForKey:(NSString *)key {
    @synchronized (lock) {
        NSUInteger index = [operationSetQueue indexOfObject:key];
        [operationSetQueue removeObjectAtIndex:index];
        [self rebuildEstimatedData];
    }
}

I can give this issue a go if no one else is doing it...

@nlutsenko
Copy link
Contributor Author

@kashif pretty close, there are a little bit more things there - availableKeys would need to be adjusted as well as we need to checkpointAllMutableContainers.
Also - operationSetQueue contains PFOperationSet objects, not just keys.

@kashif
Copy link
Contributor

kashif commented Aug 19, 2015

thanks for the info @nlutsenko just about to send a pull request. At the moment I am thinking:

- (void)revert {
    @synchronized (lock) {
        [operationSetQueue removeAllObjects];
        [self rebuildEstimatedData];
        [self checkpointAllMutableContainers];
    }
}

-(void)revertObjectForKey:(NSString *)key {
    @synchronized (lock) {
        NSUInteger index = [operationSetQueue indexOfObject:key];
        [operationSetQueue removeObjectAtIndex:index];
        [_availableKeys removeObject:key];

        PFFieldOperation *changes = [[self unsavedChanges] objectForKey:key];
        index = [operationSetQueue indexOfObject:changes];
        [operationSetQueue removeObjectAtIndex:index];

        [self rebuildEstimatedData];
        [self checkpointAllMutableContainers];
    }
}

@kashif
Copy link
Contributor

kashif commented Aug 19, 2015

thanks @grantland having a look

@grantland
Copy link

Another optimization that Android should probably have is no-oping if we're not dirty or the key isn't dirty.

@nlutsenko
Copy link
Contributor Author

Fully done. Thanks everyone.

@nlutsenko nlutsenko added this to the 1.8.2 milestone Aug 27, 2015
@nlutsenko nlutsenko self-assigned this Aug 27, 2015
@kashif
Copy link
Contributor

kashif commented Aug 27, 2015

thanks @nlutsenko for your help!

@arasu01
Copy link

arasu01 commented Sep 1, 2015

This is not fully fixed for me.
When use the 'revert' on the [PFUser currentUser], it restores to previous state when the already existing email is used.

But after killing the app and relaunching the app again and fetch the data from [PFUser currentUser] it doesn't shows up the revert data instead it shows the wrong data for which I opened the issue #51.

@nlutsenko : can you please check this.

@parse-github-assistant
Copy link

The label type:feature cannot be used in combination with type:improvement.

@parse-github-assistant parse-github-assistant bot removed the type:feature New feature or improvement of existing feature label Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants