Android Question cloudKVS - how to identify specific changes on NewData event?

Dave O

Well-Known Member
Licensed User
Longtime User
Hi cloudKVS users,

I'm updating my checklist app to share lists between users, and hope to use cloudKVS to do that - write changes to the local data store, let cloudKVS upload those to the server data store, and periodically refresh from server to the client app.

Question: When the NewData event fires (after a RefreshUser call), is there an easy way to determine which records have been updated?

For example, I'd like the UI to indicate that 4 updates happened, and the user could tap that to see which 4 records were affected.

My first thought was that the client could just remember the last time it got a NewData event, save that timestamp, and this time when new data came in, just loop through all items looking for ones that were updated since that time. (CloudKVS seems to have a timeField for each item, or I could add my own timestamp to each item.)

But when I started thinking about edge cases, I'm not sure this would work reliably. For example, when another client changes an item but their upload is delayed by network outage:
- 10am - They add item A and it uploads to the server.
- 11am - They add item B, but it doesn't upload yet because they're out of coverage.
- 12pm - I refresh and get item A (but not item B). I look for timestamps since my last refresh and find item A.
- 1pm - They return to coverage and item B uploads to the server.
- 2pm - I refresh and get item B. However, when I loop through items to get timestamps later than my last refresh (at 12pm), I don't find B (because its timestamp was 11am, based on when it was originally added to their local data store).

So not sure how I should handle this. I haven't found anything in the tutorial, comments, or on the forums. Anyone?
 

PaulMeuris

Active Member
Licensed User
If you loop through items and compare timestamps, do you use the timestamp from the server update?
Is the timestamp from the item updated with the timestamp from the server during the upload?
New Zealand has 2 timezones, right? In which timezone is the server located?
Maybe these questions give you an idea how to proceed.
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
It looks like cloudKVS timestamps use DateTime.Now, meaning they're in UTC, so that should be the same as my timestamps, wherever the clients and server are.

From a quick look at the cloudKVS code, I think the item's timestamp is assigned when it's created in the local data store, and the server keeps that initial value unless it finds a later change to that record.
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
Ah, that makes sense, because the server would only serialize and send the items that needed updating.

So I should be able to build up my own list of changed items (actually, to save space, I only need an index list of userField+KeyField, from which I can find the real items later if/when I need to).

I'm assuming I would need to build a cumulative list in case there were more items in the queue, and then when it eventually finishes the queue and calls NewData, I could include the index list as an argument in the NewData event.

If that sounds reasonable, I'm happy to try coding this and post the results as a code snippet in the Snippets channel.

Thanks!
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
I've written and tested this change and it seems to work well.

The code is available here in the Snippets channel.

Thanks all!
 
Upvote 0
Top