diff --git a/webpush/store.go b/webpush/store.go index a318f2b4..81800431 100644 --- a/webpush/store.go +++ b/webpush/store.go @@ -40,7 +40,7 @@ type storeQueries struct { selectSubscriptionCountBySubscriberIP string selectSubscriptionsForTopic string selectSubscriptionsExpiringSoon string - insertSubscription string + upsertSubscription string updateSubscriptionWarningSent string updateSubscriptionUpdatedAt string deleteSubscriptionByEndpoint string @@ -71,8 +71,7 @@ func (s *commonStore) UpsertSubscription(endpoint string, auth, p256dh, userID s } // Read existing subscription ID for endpoint (or create new ID) var subscriptionID string - err = tx.QueryRow(s.queries.selectSubscriptionIDByEndpoint, endpoint).Scan(&subscriptionID) - if errors.Is(err, sql.ErrNoRows) { + if err := tx.QueryRow(s.queries.selectSubscriptionIDByEndpoint, endpoint).Scan(&subscriptionID); errors.Is(err, sql.ErrNoRows) { if subscriptionCount >= subscriptionEndpointLimitPerSubscriberIP { return ErrWebPushTooManySubscriptions } @@ -82,7 +81,7 @@ func (s *commonStore) UpsertSubscription(endpoint string, auth, p256dh, userID s } // Insert or update subscription updatedAt, warnedAt := time.Now().Unix(), 0 - if _, err = tx.Exec(s.queries.insertSubscription, subscriptionID, endpoint, auth, p256dh, userID, subscriberIP.String(), updatedAt, warnedAt); err != nil { + if _, err := tx.Exec(s.queries.upsertSubscription, subscriptionID, endpoint, auth, p256dh, userID, subscriberIP.String(), updatedAt, warnedAt); err != nil { return err } // Replace all subscription topics diff --git a/webpush/store_postgres.go b/webpush/store_postgres.go index 831b50f3..9fb7f9f1 100644 --- a/webpush/store_postgres.go +++ b/webpush/store_postgres.go @@ -44,7 +44,7 @@ const ( FROM webpush_subscription WHERE warned_at = 0 AND updated_at <= $1 ` - postgresInsertSubscriptionQuery = ` + postgresUpsertSubscriptionQuery = ` INSERT INTO webpush_subscription (id, endpoint, key_auth, key_p256dh, user_id, subscriber_ip, updated_at, warned_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) ON CONFLICT (endpoint) @@ -80,7 +80,7 @@ func NewPostgresStore(db *sql.DB) (Store, error) { selectSubscriptionCountBySubscriberIP: postgresSelectSubscriptionCountBySubscriberIPQuery, selectSubscriptionsForTopic: postgresSelectSubscriptionsForTopicQuery, selectSubscriptionsExpiringSoon: postgresSelectSubscriptionsExpiringSoonQuery, - insertSubscription: postgresInsertSubscriptionQuery, + upsertSubscription: postgresUpsertSubscriptionQuery, updateSubscriptionWarningSent: postgresUpdateSubscriptionWarningSentQuery, updateSubscriptionUpdatedAt: postgresUpdateSubscriptionUpdatedAtQuery, deleteSubscriptionByEndpoint: postgresDeleteSubscriptionByEndpointQuery, diff --git a/webpush/store_sqlite.go b/webpush/store_sqlite.go index 6022f45f..7fe4ba3f 100644 --- a/webpush/store_sqlite.go +++ b/webpush/store_sqlite.go @@ -96,7 +96,7 @@ func NewSQLiteStore(filename, startupQueries string) (Store, error) { selectSubscriptionCountBySubscriberIP: sqliteSelectWebPushSubscriptionCountBySubscriberIPQuery, selectSubscriptionsForTopic: sqliteSelectWebPushSubscriptionsForTopicQuery, selectSubscriptionsExpiringSoon: sqliteSelectWebPushSubscriptionsExpiringSoonQuery, - insertSubscription: sqliteInsertWebPushSubscriptionQuery, + upsertSubscription: sqliteInsertWebPushSubscriptionQuery, updateSubscriptionWarningSent: sqliteUpdateWebPushSubscriptionWarningSentQuery, updateSubscriptionUpdatedAt: sqliteUpdateWebPushSubscriptionUpdatedAtQuery, deleteSubscriptionByEndpoint: sqliteDeleteWebPushSubscriptionByEndpointQuery,