Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop unique index on pending invites and fix invite key list #765

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading