don't save note if no changes made (#705)

This commit is contained in:
Damien Elmes 2013-04-11 19:20:23 +09:00
parent 735a706bc1
commit c44cf32dc2

View File

@ -43,18 +43,24 @@ from notes where id = ?""", self.id)
self.scm = self.col.scm self.scm = self.col.scm
def flush(self, mod=None): def flush(self, mod=None):
"If fields or tags have changed, write changes to disk."
assert self.scm == self.col.scm assert self.scm == self.col.scm
self._preFlush() self._preFlush()
self.mod = mod if mod else intTime()
self.usn = self.col.usn()
sfld = stripHTMLMedia(self.fields[self.col.models.sortIdx(self._model)]) sfld = stripHTMLMedia(self.fields[self.col.models.sortIdx(self._model)])
tags = self.stringTags() tags = self.stringTags()
fields = self.joinedFields()
if not mod and self.col.db.scalar(
"select 1 from notes where id = ? and tags = ? and flds = ?",
self.id, tags, fields):
return
csum = fieldChecksum(self.fields[0]) csum = fieldChecksum(self.fields[0])
self.mod = mod if mod else intTime()
self.usn = self.col.usn()
res = self.col.db.execute(""" res = self.col.db.execute("""
insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?)""", insert or replace into notes values (?,?,?,?,?,?,?,?,?,?,?)""",
self.id, self.guid, self.mid, self.id, self.guid, self.mid,
self.mod, self.usn, tags, self.mod, self.usn, tags,
self.joinedFields(), sfld, csum, self.flags, fields, sfld, csum, self.flags,
self.data) self.data)
self.col.tags.register(self.tags) self.col.tags.register(self.tags)
self._postFlush() self._postFlush()