简体   繁体   English

来自本地数据存储区的Parse.com脱机查询返回0个对象

[英]Parse.com offline query from local datastore returns 0 objects

I'm working on Android app which uses Parse and should work offline. 我正在开发使用Parse的Android应用程序,应该可以脱机工作。

Everytime as app starts in splash screen, it will run fetch recursively to fetch every single class object data from database. 每当应用程序在启动画面中启动时,它将以递归方式运行提取以从数据库中获取每个单个对象数据。 It will fetch almost 200 objects to local datastore (from simple objects to objects with relations and pointers to those simple objects) if user is online. 如果用户在线,它将把近200个对象提取到本地数据存储区(从简单对象到具有关系的对象和指向那些简单对象的指针)。

In offline mode it should load those objects from local datastore and should work same as online version. 在脱机模式下,它应该从本地数据存储区加载这些对象,并且应该与在线版本一样。

Problem is that it will not load some objects where I have to check if ParseUser.objectId is equal to pointer to User in Object(s) I want to find. 问题是它不会加载一些对象,我必须检查ParseUser.objectId是否等于我想要找到的对象中的User的指针。 This doesn`t work if you are offline. 如果您处于离线状态,这不起作用。 0 objects returned. 返回0个对象。 If you are online it is working as intended. 如果您在线,则按预期工作。

I've checked ParseUser.objectId and ACL s. 我检查了ParseUser.objectIdACL They are exactly same. 它们完全相同。 Both online and Offline user is same user (not anonymous). 在线用户和离线用户都是同一个用户(非匿名用户)。

Parse API Call: 解析API调用:

fun getItems(c: Context, itemState: Int, user: ParseUser, isShortcut: Boolean,
                         callback: (List<ParseObject>?, Boolean, ParseException?) -> Unit){

            val q = ParseQuery.getQuery<ParseObject>(ITEM_CLASS)

            q.whereEqualTo(ITEM_STATE, itemState)
            q.include(POINTER_OBJECT)
            q.include(POINTER_OBJECT_ORGANIZATION)

            if (itemState == ITEM_STATE_NEXT){
                q.whereDoesNotExist(ITEM_USER_ID)
                q.whereGreaterThan(NEXT_DATE, getCurrDate())
                q.addAscendingOrder(NEXT_DATE)
                q.whereExists(NEXT_DATE)
            } else {
                if (isOnline(c)){
                    createLog("Reports", "ONLINE:\n" +
                            "UserID: ${user.objectId}\n" +
                            "UserACL: ${user.acl}\n" +
                            "PublicRead: ${user.acl?.publicReadAccess}\n" +
                            "PublicWrite: ${user.acl?.publicWriteAccess}")
                } else {
                    createLog("Reports", "OFFLINE:\n" +
                            "UserID: ${user.objectId}\n" +
                            "UserACL: ${user.acl}\n" +
                            "PublicRead: ${user.acl?.publicReadAccess}\n" +
                            "PublicWrite: ${user.acl?.publicWriteAccess}")
                }
                q.whereEqualTo(USER_ID, user.objectId)
            }

            if (!isOnline(c)) {
                q.ignoreACLs()
                q.fromLocalDatastore()
            }

            q.findInBackground { itemList, err ->
                itemList?.let {reports ->
                    ParseObject.pinAllInBackground(reports)
                    createLog("dataPinned", "${reports.size}")
                }
                callback(itemList, isShortcut, err)
            }
        }

你可以试着在这里改变这一行吗?

q.whereEqualTo(USER_ID, user)

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

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