Minor documents updates

Hi!

We are developing a game and using Couchbase as a database.

Each player has it’s own game map. Game map is actually a JSON about 10KB in size stored as a single document in Couchbase. Also this JSON has LastActivityTime field which stores current app server timestamp. Server updates this field periodically (15 seconds) for each currently playing player. Also we have indices and views build on these docs. And the problem is that we have constant reindexing due to changing LastActivityTime. LastActivityTime is some kind of lock, because a player can play on multiple devices (like tablet and phone) on the same map, but not at the same time. So if LastActivityTime + 30 seconds >= CurrentTimestamp then app server considers player as online. Is it possible to avoid reindex when we update this field? Or use document meta data somehow to store something like LastActivityTime.

Andrew.

Afiak, Indexing always updates an index if a field is included in it. I assume you’re including LastActivityTime in one of more of your indexes?

Yes, we use that field in one view and index for N1QL query. The query is required to return players matching some criteria, but only players who is offline now.

Then I think you’ve answered your own question - if a field changes and it’s part of an index or map/reduce view, that document will need to be reindexed.

That’s the case even if there’s some additional predicate (user.offline == true) - given that until the change is examined the index / map() function won’t know if it’s applicable or not.

Thanks for reply!

Can you please confirm that the index won’t rebuild if update the doc with some changes, but field value will remain the same? The idea is to add another field like this but with less frequent updates.

Thinking about this some more, I think it’ll still need to rebuild - the issue is that the indexer (specifically the projector which listens for changes to a document) doesn’t know what the old value of the field is - so it cannot tell if that field value is actually constant or not. As such, as long as a document contains a given field and that field is part of an index, then it needs to check if the index needs updating. Once the document is checked by the indexer it’ll see it’s already indexed and not do any more.

Note this isn’t my area of expertise - I could be mistaken. Maybe someone who know more about indexing could?