简体   繁体   中英

Parse.com offline query from local datastore returns 0 objects

I'm working on Android app which uses Parse and should work offline.

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.

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. This doesn`t work if you are offline. 0 objects returned. If you are online it is working as intended.

I've checked ParseUser.objectId and ACL s. They are exactly same. Both online and Offline user is same user (not anonymous).

Parse API Call:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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