Hello,
We’re using CB lite (1.4.1) in a c# windows service that stores data for a blog. The data is synced across a couple of web servers.
We have an issue where every few weeks random instances of docs lose all their revs in the local sqlite DB (i.e. the doc is in the DB but has no revs at all).
Deleting the local DB and re-syncing fixes the issue but we’d like to find out what the possible source of this could be.
We have one function that updates docs and I was wondering if it’s implemented incorrectly (see below). Any suggestions?
Thank you
EDIT:
A correction on my initial statement: The revs are not deleted, but they contain no data (i.e. json field is NULL) and the current field is ‘0’. So it seems that the ‘current’ rev is missing, not all of them.
private Document CreateOrUpdateDocumentWithJsonAttachments(string docId, Dictionary<string, object> properties, Dictionary<string, byte[]> attachments, bool existingOnly, DateTime? expireAt)
{
if (properties == null && (attachments == null || attachments.Count == 0))
{
Debug.Assert(false);
return null;
}
Document doc = (existingOnly) ? _Database.GetExistingDocument(docId) : _Database.GetDocument(docId);
if (doc == null)
{
Debug.Assert(existingOnly);
return null;
}
string docType = TypeForDocumentId(docId);
Debug.Assert(docType != null);
if (properties != null)
{
properties["type"] = docType;
properties["syncUserId"] = "xyz";
}
SavedRevision sr = doc.Update((UnsavedRevision newRevision) =>
{
if (properties != null)
{
newRevision.SetProperties(properties);
}
if (attachments != null)
{
foreach (KeyValuePair<string, byte[]> pair in attachments)
{
if (pair.Value == null)
{
newRevision.RemoveAttachment(pair.Key);
}
else
{
newRevision.SetAttachment(pair.Key, "application/json", pair.Value);
}
}
}
else if (doc.CurrentRevision != null && doc.CurrentRevision.Attachments != null)
{
foreach (Attachment att in doc.CurrentRevision.Attachments)
{
newRevision.SetAttachment(att.Name, att.ContentType, att.Content);
}
}
#if DEBUG
Debug.WriteLine(string.Format("Saved: {0}", doc.Id));
#endif
return true;
});
if (expireAt.HasValue)
{
doc.ExpireAt(expireAt);
}
return doc;
}