Monorepo for Tangled tangled.org

knotserver: switch timestamps to unix nanos

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li 95c3f149 fe8c96f0

verified
Changed files
+8 -2
knotserver
+3 -1
knotserver/db/events.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 + "time" 5 6 6 7 "tangled.sh/tangled.sh/core/notifier" 7 8 ) ··· 16 17 func (d *DB) InsertEvent(event Event, notifier *notifier.Notifier) error { 17 18 18 19 _, err := d.db.Exec( 19 - `insert into events (rkey, nsid, event) values (?, ?, ?)`, 20 + `insert into events (rkey, nsid, event, created) values (?, ?, ?, ?)`, 20 21 event.Rkey, 21 22 event.Nsid, 22 23 event.EventJson, 24 + time.Now().UnixNano(), 23 25 ) 24 26 25 27 notifier.NotifyAll()
+5 -1
knotserver/events.go
··· 43 43 } 44 44 }() 45 45 46 + defaultCursor := time.Now().UnixNano() 46 47 cursorStr := r.URL.Query().Get("cursor") 47 48 cursor, err := strconv.ParseInt(cursorStr, 10, 64) 48 49 if err != nil { 49 - l.Error("empty or invalid cursor, defaulting to zero", "invalidCursor", cursorStr) 50 + l.Error("empty or invalid cursor", "invalidCursor", cursorStr, "default", defaultCursor) 51 + } 52 + if cursor == 0 { 53 + cursor = defaultCursor 50 54 } 51 55 52 56 // complete backfill first before going to live data