1
0

fix(subscriptions): cleanup and simplify fetching subscribers for tasks and projects logic

Vikunja now uses one recursive CTE and a few optimizations to fetch all subscribers for a task or project. This makes the relevant code easier to maintain and more performant.

(cherry picked from commit 4ff8815fe1bfe72e02c10f6a6877c93a630f36a4)
This commit is contained in:
kolaente
2024-09-04 19:54:22 +02:00
parent 7646c7f0c9
commit 8b8ec19bb3
7 changed files with 330 additions and 265 deletions

View File

@ -1745,7 +1745,7 @@ func IsErrSubscriptionAlreadyExists(err error) bool {
}
func (err *ErrSubscriptionAlreadyExists) Error() string {
return fmt.Sprintf("Subscription for this (entity_id, entity_type, user_id) already exists [EntityType: %d, EntityID: %d, ID: %d]", err.EntityType, err.EntityID, err.UserID)
return fmt.Sprintf("Subscription for this (entity_id, entity_type, user_id) already exists [EntityType: %d, EntityID: %d, UserID: %d]", err.EntityType, err.EntityID, err.UserID)
}
// ErrCodeSubscriptionAlreadyExists holds the unique world-error code of this error
@ -1760,6 +1760,32 @@ func (err ErrSubscriptionAlreadyExists) HTTPError() web.HTTPError {
}
}
// ErrMustProvideUser represents an error where you need to provide a user to fetch subscriptions
type ErrMustProvideUser struct {
}
// IsErrMustProvideUser checks if an error is ErrMustProvideUser.
func IsErrMustProvideUser(err error) bool {
_, ok := err.(*ErrMustProvideUser)
return ok
}
func (err *ErrMustProvideUser) Error() string {
return "no user provided while fetching subscriptions"
}
// ErrCodeMustProvideUser holds the unique world-error code of this error
const ErrCodeMustProvideUser = 12003
// HTTPError holds the http error description
func (err ErrMustProvideUser) HTTPError() web.HTTPError {
return web.HTTPError{
HTTPCode: http.StatusPreconditionFailed,
Code: ErrCodeMustProvideUser,
Message: "You must provide a user to fetch subscriptions",
}
}
// =================
// Link Share errors
// =================