Use item.ID for uniqueness
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Peter Stuifzand 2021-10-31 19:49:47 +01:00
parent 145fdd8a79
commit 8977ae6a0c
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -211,7 +211,7 @@ func (p *postgresStream) AddItem(item microsub.Item) (bool, error) {
}
t = t2
}
if item.UID == "" {
if item.ID == "" {
// FIXME: This won't work when we receive the item multiple times
h := sha256.Sum256([]byte(fmt.Sprintf("%s:%d", p.channel, time.Now().UnixNano())))
item.UID = hex.EncodeToString(h[:])
@ -236,7 +236,7 @@ func (p *postgresStream) AddItem(item microsub.Item) (bool, error) {
INSERT INTO "items" ("channel_id", "feed_id", "uid", "data", "published_at", "created_at")
VALUES ($1, $2, $3, $4, $5, DEFAULT)
ON CONFLICT ON CONSTRAINT "items_uid_key" DO NOTHING
`, p.channelID, optFeedID, item.UID, &item, t)
`, p.channelID, optFeedID, item.ID, &item, t)
if err != nil {
return false, fmt.Errorf("insert item: %w", err)
}