Compare commits

...

2 Commits

Author SHA1 Message Date
eba40a4eee
Problem: before pagination shows first items
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
Solution: use greater than to filter first item
2022-04-16 23:56:06 +02:00
13484d1834
Problem: no events is sent when a channel is created
Solution: fix bug when checking if channel was created
2022-04-16 23:55:10 +02:00
2 changed files with 4 additions and 4 deletions

View File

@ -186,7 +186,7 @@ func (b *memoryBackend) ChannelsCreate(name string) (microsub.Channel, error) {
for {
varMicrosub.Add("ChannelsCreate.RandStringBytes", 1)
channel.UID = util.RandStringBytes(24)
result, err := b.database.Exec(`insert into "channels" ("uid", "name", "created_at") values($1, $2, DEFAULT)`, channel.UID, channel.Name)
result, err := b.database.Exec(`insert into "channels" ("uid", "name", "created_at") values ($1, $2, DEFAULT)`, channel.UID, channel.Name)
if err != nil {
log.Println("channels insert", err)
if !shouldRetryWithNewUID(err, try) {
@ -195,7 +195,7 @@ func (b *memoryBackend) ChannelsCreate(name string) (microsub.Channel, error) {
try++
continue
}
if n, err := result.RowsAffected(); err != nil {
if n, err := result.RowsAffected(); err == nil {
if n > 0 {
b.broker.Notifier <- sse.Message{Event: "new channel", Object: channelMessage{1, channel}}
}

View File

@ -127,7 +127,7 @@ WHERE "channel_id" = $1
log.Println(err)
} else {
args = append(args, b)
qb.WriteString(` AND "published_at" >= $2`)
qb.WriteString(` AND "published_at" > $2`)
}
} else if after != "" {
b, err := time.Parse(time.RFC3339, after)
@ -196,7 +196,7 @@ WHERE "channel_id" = $1
}
func hasMoreBefore(conn *sql.Conn, before string) bool {
row := conn.QueryRowContext(context.Background(), `SELECT COUNT(*) FROM "items" WHERE "published_at" >= $1`, before)
row := conn.QueryRowContext(context.Background(), `SELECT COUNT(*) FROM "items" WHERE "published_at" > $1`, before)
var count int
if err := row.Scan(&count); err == sql.ErrNoRows {
return false