Parse.com - 查找已删除的对象 [英] Parse.com - Find deleted objects

查看:29
本文介绍了Parse.com - 查找已删除的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与 Parse.com 同步的 iOS 应用.

I have an iOS app that synchronises to Parse.com.

它可以找到任何添加到 Parse 的内容,并使用 PFQuery 将其添加到 Core Data.它还可以检查任何已更新的数据并进行相应更新.

It can find anything that was added to Parse and add it to Core Data using PFQuery. It can also check for any data that has been updated and update accordingly.

但是,我不确定如何在 Parse.com 上找到已删除的对象.

However, I'm not sure how to find objects that have been deleted on Parse.com.

有谁知道将列出已删除的 ObjectID 及其删除日期的查询?然后我可以从应用程序的核心数据中删除它们.

Does anyone know of a query that will list the ObjectIDs that have been deleted and the date of their deletion? I can then remove them from the Core Data on the app.

推荐答案

我也需要这个函数,但我认为将行标记为已删除会使数据膨胀并为每个查询添加一个条件.所以我创建了一个删除类.它只记录任何已删除行的类名和 ID,因此它保持很小:

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:

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();});
});

我的 iOS 客户端记录他们上次获取数据的日期,然后从 MyClass(+ 其他)和 Deletion 获取新创建/更新的所有内容.这样,就可以在本地删除删除.

My iOS clients record the date when they last fetched data, then get everything newly created/updated from MyClass (+ others) and 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).

这篇关于Parse.com - 查找已删除的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆