android – SaveAllInBackground根据需要在deleteAllInBackground中不起作用

SaveAllInBackground根据需要在deleteallInBackground中不起作用.

我正在尝试使用后台全部保存来保存一个parSEObjects列表.为了避免表中的重复,我正在查询已存在的行并删除它们(如果有)然后保存新副本.因此我在deleteallInBackground的回调中调用saveAllInBackground.

问题是这样的:

例如:如果要删除的列表包含[a,b,c,d],并且要上传的列表包含[a,d,e,f],则只有[e,f]才能进行解析.我将[a,f]传递给saveAllInBackground但只保留了[e,f].

>有什么我想念的吗?怎么解决这个?
>我可以使用不同的方法吗?
>有没有更好的方法来避免重复?我不想添加一个
beforeSave hook.调用saveAll的全部目的是减少API调用数量.我想如果我使用beforeSave,我将不得不在云代码中运行一些查询.

这是我的代码

ParseQuery query = new ParseQuery("PostChoice");

            query.fromPin();
            query.findInBackground(new FindCallback<ParSEObject>() {
                @Override
                public void done(final List<ParSEObject> localList,ParseException e) {
                    if (localList != null && !localList.isEmpty()) {
                        List<ParSEObject> postList = new ArrayList<ParSEObject>();
                        for (ParSEObject object : localList) {

                            postList.add(object.getParSEObject("post"));
                        }
                        ParseQuery query = new ParseQuery("PostChoice");
                        query.whereContainedIn("post",postList);
                        query.whereEqualTo("user",ParseUser.getCurrentUser());
                        query.findInBackground(new FindCallback<ParSEObject>() {
                            @Override
                            public void done(List<ParSEObject> parseCloudList,ParseException e) {

                                if (parseCloudList != null && !parseCloudList.isEmpty()) {
                                    ParSEObject.deleteallInBackground(parseCloudList,new DeleteCallback() {
                                        @Override
                                        public void done(ParseException e) {
               // this gets executed and rows are accordingly deleted                             
                                            ParSEObject.saveAllInBackground(localList,new SaveCallback() {
                                                @Override
                                                public void done(ParseException e) {
// this gets executed but the rows are not uploaded. 
//the locallist is not empty. it contains the right data.
                                                    editor.putLong(Four.LAST_CHOICE_SYNC_TIME,System.currentTimeMillis());
                                                    editor.commit();
                                                    Log.i("SyncChoiceService","Synced Choices");
                                                }
                                            });
                                        }
                                    });
                                }
                                else{
                                    ParSEObject.saveAllInBackground(localList,new SaveCallback() {
                                        @Override
                                        public void done(ParseException e) {
                                            Log.i("SyncChoiceService","Synced Choices");
                                            editor.putLong(Four.LAST_CHOICE_SYNC_TIME,System.currentTimeMillis());
                                            editor.commit();
                                        }
                                    });
                                }
                            }
                        });


                    }
                }
            });

解决方法

我想出了这样的解决方案.它符合我的要求.我使用updatedValue并删除旧的,其余的更新作为整个列表.
ParseQuery query = new ParseQuery("PostChoice");

            query.fromPin();
            query.findInBackground(new FindCallback<ParSEObject>() {
                @Override
                public void done(final List<ParSEObject> localList,ParseException e) {
                    if (localList != null && !localList.isEmpty()) {

                        List<ParSEObject> postList = new ArrayList<ParSEObject>();
                        for (ParSEObject object : localList) {

                            postList.add(object.getParSEObject("post"));
                        }
                        ParseQuery query = new ParseQuery("PostChoice");
                        query.whereContainedIn("post",postList);
                        query.whereLessthan("updatedAt",System.currentTimeMillis());
                        query.whereEqualTo("user",ParseUser.getCurrentUser());
                        query.findInBackground(new FindCallback<ParSEObject>() {
                            @Override
                            public void done(final List<ParSEObject> parseCloudList,ParseException e) {
                                if (parseCloudList != null && !parseCloudList.isEmpty()) {
                                    ParSEObject.deleteallInBackground(parseCloudList,new DeleteCallback() {
                                        @Override
                                        public void done(ParseException e) {
                                            Log.i("SyncChoiceService","Deleted old  Choices");

                                        }
                                    });
                                }


                                    }
                                });


ParSEObject.saveAllInBackground(localList,new SaveCallback() {
        @Override
        public void done(ParseException e) {
            Log.i("SyncChoiceService","Synced Choices");
        }
    });

                    }
                }
            });

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...