Skip to content

Commit

Permalink
Drop unique index on pending invites and fix invite key list (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteStash authored Feb 28, 2024
1 parent 61e8dcb commit 0a05b9c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/jmoiron/sqlx"
)

var appSchemaVersion uint = 35
var appSchemaVersion uint = 36

var databaseProviders map[string]databaseProvider

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP INDEX IF EXISTS "pending_activation_invite_key_idx";
9 changes: 7 additions & 2 deletions pkg/sqlx/querybuilder_invite_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ func (qb *inviteKeyQueryBuilder) Find(id uuid.UUID) (*models.InviteKey, error) {

func (qb *inviteKeyQueryBuilder) FindActiveKeysForUser(userID uuid.UUID, expireTime time.Time) (models.InviteKeys, error) {
query := `SELECT i.* FROM ` + inviteKeyTable + ` i
LEFT JOIN ` + pendingActivationTable + ` a ON a.invite_key = i.id AND a.time > ?
WHERE i.generated_by = ? AND a.id IS NULL`
LEFT JOIN (
SELECT invite_key, COUNT(*) as count
FROM pending_activations
WHERE time > ?
GROUP BY invite_key
) a ON a.invite_key = i.id
WHERE i.generated_by = ? AND (a.invite_key IS NULL OR i.uses IS NULL OR a.count < i.uses)`
var args []interface{}
args = append(args, expireTime)
args = append(args, userID)
Expand Down

0 comments on commit 0a05b9c

Please sign in to comment.