Expiry functions doesnt work when document is updated from N1QL


#1

When I am updating the document from N1QL the expiry function called inside the sync function of the sync gateway doesn’t work and doesnt set the expiry time of the document. But If I update the document through sync gateway the expiry is set and document get deleted at the correct time.

Do note that the change done by N1QL does reflect when the get operation is done. So it means import is done properly. Only doubt I am having is about the sync function.

I am using CBS 5.1.1 and SG 2.0.

Following is my sync gateway config :slight_smile :

{
“server”: “http://***.***.***.***,***.***.***.:8091",
“pool”: “default”,
“bucket”: “bucketname”,
“username”: “bucketname”,
“password”: “password”,
“name”: “username”,
“sync”:`function(doc, oldDoc)
{
if(doc.type)
{
if(doc.type == “GuestAdditionalInformation” || doc.type == “BoardingAdditionalInformation” || doc.type == “Multimedia”)
{
if(doc.lastModifiedDate)
{
var dttimeStamp = new Date(doc.lastModifiedDate).getTime();
dttimeStamp=dttimeStamp+(15 * 24 * 3600 * 1000);
expiry(new Date(dttimeStamp).toISOString());
}
else
{
expiry(“3600”);
}
}
}

if(doc.ExpiryDateEpoch)
{
	var dtexpiryDateEpoch = new Date(doc.ExpiryDateEpoch).getTime();
	expiry(new Date(dtexpiryDateEpoch).toISOString());
}

if(doc.channels)     
	channel(doc.channels);

}`,
“users”: {
“GUEST”: {
“name”: “”,
“all_channels”: null,
“disabled”: true
},
“Xuser”: {
“name”: “Xuser”,
“admin_channels”: [
“”
],
“all_channels”: null,
“password”: “”
},
“Yuser”: {
“name”: “Yuser”,
“admin_channels”: [
“”
],
“all_channels”: null,
“password”: "”
}
},
“import_docs”: “continuous”,
“cache”: {
“enable_star_channel”: null,
“channel_cache_max_length”: 100000,
“channel_cache_min_length”: 50,
“channel_cache_expiry”: 600
},
“rev_cache_size”: 200000,
“unsupported”: {
“user_views”: {},
“oidc_test_provider”: {}
},
“enable_shared_bucket_access”: true,
“session_cookie_name”: “”
}

CC :- @househippo, @adamf , @traun


#2

And I think this was working fine in 5.1.


#3

There shouldn’t be any difference in expiry handling between updates made directly through Sync Gateway, versus import of changes made via N1QL. The same code path will be executed for sync function execution and subsequent document update (including expiry), and if you’re seeing the document being properly imported, there shouldn’t be any potential issue there.

If there is a new issue introduced regarding expiry handling between 5.1 and 5.1.1 I’d expect it to apply to both SG writes and SG imports.

Are you certain you’re hitting the same code path in your sync function for the SG and N1QL update cases?


#4

I think this is an intermittent issue. The same document when updated multiple times XATTRs sometime shows the expiration time in the document window of couchbase and _raw rest api of the sync gateway but then this doesnt work some times for the same document. I would let you know if I can find exact issue.