简体   繁体   English

Parse.com-查找已删除的对象

[英]Parse.com - Find deleted objects

I have an iOS app that synchronises to Parse.com. 我有一个与Parse.com同步的iOS应用程序。

It can find anything that was added to Parse and add it to Core Data using PFQuery. 它可以找到添加到Parse的任何内容,然后使用PFQuery将其添加到Core Data中。 It can also check for any data that has been updated and update accordingly. 它还可以检查是否有任何已更新的数据并相应地更新。

However, I'm not sure how to find objects that have been deleted on Parse.com. 但是,我不确定如何查找在Parse.com上已删除的对象。

Does anyone know of a query that will list the ObjectIDs that have been deleted and the date of their deletion? 有谁知道一个查询,该查询将列出已删除的ObjectID及其删除日期? I can then remove them from the Core Data on the app. 然后,我可以从应用程序的核心数据中删除它们。

I needed this function, too, but figured that marking rows as deleted will bloat the data and add a condition to every query. 我也需要此功能,但认为将行标记为已删除将使数据膨胀并为每个查询添加条件。 So I created a Deletion class. 所以我创建了一个删除类。 It records only the class name and ID of any deleted row, so it stays pretty small: 它仅记录任何已删除行的类名和ID,因此它保持很小:

function recordDeletion(klass, identifier) {
    var Deletion = Parse.Object.extend("Deletion");
    var deletion = new Deletion();
    deletion.set("klass", klass);
    deletion.set("identifier", identifier);
    return deletion.save();
}

// for every class that you want deletions recorded, add one of these...
Parse.Cloud.beforeDelete("MyClass", function(request, response) {
    recordDeletion("MyClass", request.object.id).then(function() {response.success();});
});

My iOS clients record the date when they last fetched data, then get everything newly created/updated from MyClass (+ others) and Deletion . 我的iOS客户端记录了他们最后一次获取数据的日期,然后从MyClass (+其他)和Deletion获取新创建/更新的所有内容。 With that, the can delete the Deletions locally. 这样,可以在本地删除“删除”。

Over a longer period, the clients remove all of the locally cached data and get a fresh copy of everything (except Deletions). 在较长的一段时间内,客户端会删除所有本地缓存​​的数据,并获得所有内容的新副本(“删除”除外)。 This allows me to have a scheduled job on the server that will empty the Deletion table (on a cycle that's much longer than the client's cycle). 这使我在服务器上有一个计划的作业,该作业将清空“删除”表(一个周期长于客户端的周期)。

There is no provided API for this. 没有为此提供的API。

As per the comment from @Fogmeister you can tag objects as deleted and update like that. 根据@Fogmeister的评论,您可以将对象标记为已删除并进行更新。 Alternatively you can maintain a specific list of deleted ids (potentially using Parse.Cloud.beforeDelete ) and then make a specific request to get only the deletions. 或者,您可以维护已删除ID的特定列表(可能使用Parse.Cloud.beforeDelete ),然后发出特定请求以仅获取删除内容。

In either case you will need to explicitly manage the scheme you choose and also decide how and when to clean up the deleted objects / deletion records. 无论哪种情况,您都需要显式管理您选择的方案,并决定如何以及何时清理已删除的对象/删除记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM