fix: dedupe compares bytes to characters, so every Unicode body appended a duplicate (#51)
fix: dedupe compares bytes to characters, so every Unicode body appended a duplicate (#51) Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
This commit was merged in pull request #51.
This commit is contained in:
+5
-1
@@ -360,9 +360,13 @@ func (k *KnoxDB) RecordObservation(o ObservationRecord) (obsID int64, isNew bool
|
||||
err = tx.QueryRow(
|
||||
`SELECT id, COALESCE(title,''), COALESCE(summary,''), COALESCE(project,''),
|
||||
COALESCE(created_at,''), COALESCE(line_start,0), COALESCE(line_end,0),
|
||||
COALESCE(content_hash,''), COALESCE(LENGTH(content),0)
|
||||
COALESCE(content_hash,''), COALESCE(LENGTH(CAST(content AS BLOB)),0)
|
||||
FROM observations WHERE fingerprint=? ORDER BY hcl DESC, id DESC LIMIT 1`, o.Fingerprint,
|
||||
).Scan(&prevID, &pTitle, &pSummary, &pProject, &pCreated, &pStart, &pEnd, &pContent, &pContentLen)
|
||||
// Byte length, not characters. len() counts bytes; LENGTH() on a TEXT value
|
||||
// counts characters, so the two disagree for any body with an em dash or a
|
||||
// curly quote — and every sweep then appends a duplicate of identical
|
||||
// content. The CAST keeps SQLite on the same scale as Go.
|
||||
sameContent := int64(len(o.Content)) == pContentLen
|
||||
switch err {
|
||||
case nil:
|
||||
|
||||
Reference in New Issue
Block a user