feat(storage): add native PostgreSQL runtime and verified offline application import
Build and publish container images / images (push) Failing after 12m29s
Build and publish container images / images (push) Failing after 12m29s
This commit is contained in:
1 parent
96065d1e89
commit
0ba1dcfef0
243 files changed
+21441
-3090
No files matched your search
+71
-49
@@ -61,6 +61,17 @@ type TaskQuery struct {
|
||||
}
|
||||
|
||||
func (s *Store) EnsureTasksSchema() error {
|
||||
if s.ReadOnly {
|
||||
return ErrReadOnly
|
||||
}
|
||||
if s.sqlBackend == storePostgreSQL {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
||||
defer cancel()
|
||||
if err := s.ensurePostgreSQLTasksFoundation(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.ensurePostgreSQLTaskProductivity(ctx)
|
||||
}
|
||||
for _, q := range []string{
|
||||
`CREATE TABLE IF NOT EXISTS organizer_items (
|
||||
domain_uuid TEXT NOT NULL,owner_uuid TEXT NOT NULL,uuid TEXT NOT NULL,
|
||||
@@ -197,13 +208,17 @@ func validateTask(item *TaskRecord) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// The source of authority is checked again in the same SQLite writer transaction
|
||||
// The source of authority is checked again in the same writer transaction
|
||||
// as the conditional head, revision and change-journal commit.
|
||||
func taskActor(ctx context.Context, q interface {
|
||||
func (s *Store) taskActor(ctx context.Context, q interface {
|
||||
QueryRowContext(context.Context, string, ...any) *sql.Row
|
||||
}, domain, actor string, write bool) error {
|
||||
var allowed bool
|
||||
err := q.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM principals p JOIN domain_memberships m ON m.principal_uuid=p.uuid JOIN domains d ON d.uuid=m.domain_uuid WHERE p.uuid=? AND m.domain_uuid=? AND m.state='active' AND d.enabled=1 AND COALESCE(d.placement,'local')='local' AND (p.state='active' OR (?=0 AND p.state='readonly')))`, actor, domain, write).Scan(&allowed)
|
||||
campusJoin := ""
|
||||
if s.sqlBackend == storePostgreSQL {
|
||||
campusJoin = " JOIN campuses c ON c.uuid=d.campus_uuid AND c.enabled=1"
|
||||
}
|
||||
err := q.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM principals p JOIN domain_memberships m ON m.principal_uuid=p.uuid JOIN domains d ON d.uuid=m.domain_uuid`+campusJoin+` WHERE p.uuid=`+s.sqlParam(1)+` AND m.domain_uuid=`+s.sqlParam(2)+` AND m.state='active' AND d.enabled=1 AND COALESCE(d.placement,'local')='local' AND (p.state='active' OR (`+s.sqlParam(3)+`=0 AND p.state='readonly')))`, actor, domain, boolToInt(write)).Scan(&allowed)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -218,7 +233,8 @@ func (s *Store) SaveTask(ctx context.Context, domain, actor string, item TaskRec
|
||||
}
|
||||
|
||||
// prepare participates in the same writer transaction as the task head.
|
||||
func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRecord, expected int64, prepare func(*sql.Tx, *TaskRecord, TaskRecord) error) (TaskRecord, error) {
|
||||
func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRecord, expected int64, prepare func(*sql.Tx, *TaskRecord, TaskRecord) error) (result TaskRecord, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("task repository", resultErr) }()
|
||||
if s.ReadOnly {
|
||||
return TaskRecord{}, ErrReadOnly
|
||||
}
|
||||
@@ -232,14 +248,17 @@ func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRec
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE domain_memberships SET state=state WHERE domain_uuid=? AND principal_uuid=?`, domain, actor); err != nil {
|
||||
if err = s.lockTaskWriter(ctx, tx); err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
if err = taskActor(ctx, tx, domain, actor, true); err != nil {
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE domain_memberships SET state=state WHERE domain_uuid=`+s.sqlParam(1)+` AND principal_uuid=`+s.sqlParam(2)+``, domain, actor); err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
if err = s.taskActor(ctx, tx, domain, actor, true); err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
var rawConfig string
|
||||
err = tx.QueryRowContext(ctx, `SELECT value FROM config WHERE domain_uuid=? AND key='system_extension_states'`, domain).Scan(&rawConfig)
|
||||
err = tx.QueryRowContext(ctx, `SELECT value FROM config WHERE domain_uuid=`+s.sqlParam(1)+` AND key='system_extension_states'`, domain).Scan(&rawConfig)
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
@@ -251,7 +270,7 @@ func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRec
|
||||
return TaskRecord{}, ErrAccessDenied
|
||||
}
|
||||
var deletedOwner string
|
||||
err = tx.QueryRowContext(ctx, `SELECT owner_uuid FROM organizer_task_deletions WHERE domain_uuid=? AND item_uuid=?`, domain, item.UUID).Scan(&deletedOwner)
|
||||
err = tx.QueryRowContext(ctx, `SELECT owner_uuid FROM organizer_task_deletions WHERE domain_uuid=`+s.sqlParam(1)+` AND item_uuid=`+s.sqlParam(2)+``, domain, item.UUID).Scan(&deletedOwner)
|
||||
if err == nil {
|
||||
if deletedOwner != actor {
|
||||
return TaskRecord{}, sql.ErrNoRows
|
||||
@@ -263,7 +282,7 @@ func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRec
|
||||
}
|
||||
if item.NotifyDue || item.NotifyPlanned {
|
||||
item.ReminderTimezone = "UTC"
|
||||
err = tx.QueryRowContext(ctx, `SELECT value FROM config WHERE domain_uuid=? AND key='timezone'`, domain).Scan(&item.ReminderTimezone)
|
||||
err = tx.QueryRowContext(ctx, `SELECT value FROM config WHERE domain_uuid=`+s.sqlParam(1)+` AND key='timezone'`, domain).Scan(&item.ReminderTimezone)
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
@@ -272,7 +291,7 @@ func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRec
|
||||
}
|
||||
}
|
||||
var oldJSON, owner string
|
||||
err = tx.QueryRowContext(ctx, `SELECT data,owner_uuid FROM organizer_items WHERE domain_uuid=? AND uuid=?`, domain, item.UUID).Scan(&oldJSON, &owner)
|
||||
err = tx.QueryRowContext(ctx, `SELECT data,owner_uuid FROM organizer_items WHERE domain_uuid=`+s.sqlParam(1)+` AND uuid=`+s.sqlParam(2)+``, domain, item.UUID).Scan(&oldJSON, &owner)
|
||||
var old TaskRecord
|
||||
if err == nil {
|
||||
if owner != actor {
|
||||
@@ -305,7 +324,7 @@ func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRec
|
||||
}
|
||||
if item.ProjectUUID != "" && item.ProjectUUID != old.ProjectUUID {
|
||||
var exists bool
|
||||
err = tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND uuid=? AND kind='project' AND archived=0)`, domain, actor, item.ProjectUUID).Scan(&exists)
|
||||
err = tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM organizer_items WHERE domain_uuid=`+s.sqlParam(1)+` AND owner_uuid=`+s.sqlParam(2)+` AND uuid=`+s.sqlParam(3)+` AND kind='project' AND archived=0)`, domain, actor, item.ProjectUUID).Scan(&exists)
|
||||
if err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
@@ -317,7 +336,7 @@ func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRec
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
if item.AssigneeUUID != old.AssigneeUUID {
|
||||
if err = validateTaskAssignee(ctx, tx, domain, item.AssigneeUUID); err != nil {
|
||||
if err = s.validateTaskAssignee(ctx, tx, domain, item.AssigneeUUID); err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
}
|
||||
@@ -330,12 +349,12 @@ func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRec
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
}
|
||||
if err = syncTaskDAVTx(ctx, tx, domain, actor, item); err != nil {
|
||||
if err = s.syncTaskDAVTx(ctx, tx, domain, actor, item); err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
if item.PageUUID != "" && item.PageUUID != old.PageUUID {
|
||||
var exists bool
|
||||
err = tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM paths WHERE domain_uuid=? AND object_uuid=?)`, domain, item.PageUUID).Scan(&exists)
|
||||
err = tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM paths WHERE domain_uuid=`+s.sqlParam(1)+` AND object_uuid=`+s.sqlParam(2)+`)`, domain, item.PageUUID).Scan(&exists)
|
||||
if err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
@@ -364,18 +383,18 @@ func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRec
|
||||
if err = s.persistDocument(hash, string(b)); err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO organizer_items(domain_uuid,owner_uuid,uuid,kind,project_uuid,title,status,bucket,due_on,planned_on,review_on,archived,version,created_at_ms,updated_at_ms,data,document_hash) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT(domain_uuid,uuid) DO UPDATE SET project_uuid=excluded.project_uuid,title=excluded.title,status=excluded.status,bucket=excluded.bucket,due_on=excluded.due_on,planned_on=excluded.planned_on,review_on=excluded.review_on,archived=excluded.archived,version=excluded.version,updated_at_ms=excluded.updated_at_ms,data=excluded.data,document_hash=excluded.document_hash`, domain, actor, item.UUID, item.Kind, item.ProjectUUID, item.Title, item.Status, item.Bucket, item.DueOn, item.PlannedOn, item.ReviewOn, item.Archived, item.Version, item.CreatedMS, item.UpdatedMS, string(b), hash)
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO organizer_items(domain_uuid,owner_uuid,uuid,kind,project_uuid,title,status,bucket,due_on,planned_on,review_on,archived,version,created_at_ms,updated_at_ms,data,document_hash) VALUES(`+s.sqlParam(1)+`,`+s.sqlParam(2)+`,`+s.sqlParam(3)+`,`+s.sqlParam(4)+`,`+s.sqlParam(5)+`,`+s.sqlParam(6)+`,`+s.sqlParam(7)+`,`+s.sqlParam(8)+`,`+s.sqlParam(9)+`,`+s.sqlParam(10)+`,`+s.sqlParam(11)+`,`+s.sqlParam(12)+`,`+s.sqlParam(13)+`,`+s.sqlParam(14)+`,`+s.sqlParam(15)+`,`+s.sqlParam(16)+`,`+s.sqlParam(17)+`) ON CONFLICT(domain_uuid,uuid) DO UPDATE SET project_uuid=excluded.project_uuid,title=excluded.title,status=excluded.status,bucket=excluded.bucket,due_on=excluded.due_on,planned_on=excluded.planned_on,review_on=excluded.review_on,archived=excluded.archived,version=excluded.version,updated_at_ms=excluded.updated_at_ms,data=excluded.data,document_hash=excluded.document_hash`, domain, actor, item.UUID, item.Kind, item.ProjectUUID, item.Title, item.Status, item.Bucket, item.DueOn, item.PlannedOn, item.ReviewOn, boolToInt(item.Archived), item.Version, item.CreatedMS, item.UpdatedMS, string(b), hash)
|
||||
if err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE organizer_items SET parent_uuid=?,start_on=?,end_on=? WHERE domain_uuid=? AND uuid=?`, item.ParentUUID, item.StartOn, item.EndOn, domain, item.UUID); err != nil {
|
||||
if _, err = tx.ExecContext(ctx, `UPDATE organizer_items SET parent_uuid=`+s.sqlParam(1)+`,start_on=`+s.sqlParam(2)+`,end_on=`+s.sqlParam(3)+` WHERE domain_uuid=`+s.sqlParam(4)+` AND uuid=`+s.sqlParam(5)+``, item.ParentUUID, item.StartOn, item.EndOn, domain, item.UUID); err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO organizer_revisions(domain_uuid,item_uuid,version,actor_uuid,document_hash,created_at_ms) VALUES(?,?,?,?,?,?)`, domain, item.UUID, item.Version, actor, hash, now)
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO organizer_revisions(domain_uuid,item_uuid,version,actor_uuid,document_hash,created_at_ms) VALUES(`+s.sqlParam(1)+`,`+s.sqlParam(2)+`,`+s.sqlParam(3)+`,`+s.sqlParam(4)+`,`+s.sqlParam(5)+`,`+s.sqlParam(6)+`)`, domain, item.UUID, item.Version, actor, hash, now)
|
||||
if err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO organizer_changes(domain_uuid,item_uuid,version,actor_uuid,created_at_ms) VALUES(?,?,?,?,?)`, domain, item.UUID, item.Version, actor, now)
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO organizer_changes(domain_uuid,item_uuid,version,actor_uuid,created_at_ms) VALUES(`+s.sqlParam(1)+`,`+s.sqlParam(2)+`,`+s.sqlParam(3)+`,`+s.sqlParam(4)+`,`+s.sqlParam(5)+`)`, domain, item.UUID, item.Version, actor, now)
|
||||
if err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
@@ -386,7 +405,7 @@ func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRec
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
if item.Kind == "task" {
|
||||
if _, err = tx.ExecContext(ctx, `INSERT INTO organizer_task_metrics VALUES(?,?,?,?,?,?) ON CONFLICT(domain_uuid,task_uuid) DO UPDATE SET completed_ms=excluded.completed_ms,estimate=excluded.estimate,complexity=excluded.complexity`, domain, actor, item.UUID, item.CompletedMS, item.Estimate, max(1, item.Complexity)); err != nil {
|
||||
if _, err = tx.ExecContext(ctx, `INSERT INTO organizer_task_metrics VALUES(`+s.sqlParam(1)+`,`+s.sqlParam(2)+`,`+s.sqlParam(3)+`,`+s.sqlParam(4)+`,`+s.sqlParam(5)+`,`+s.sqlParam(6)+`) ON CONFLICT(domain_uuid,task_uuid) DO UPDATE SET completed_ms=excluded.completed_ms,estimate=excluded.estimate,complexity=excluded.complexity`, domain, actor, item.UUID, item.CompletedMS, item.Estimate, max(1, item.Complexity)); err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
}
|
||||
@@ -396,12 +415,13 @@ func (s *Store) saveTask(ctx context.Context, domain, actor string, item TaskRec
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (s *Store) GetTask(ctx context.Context, domain, actor, id string) (TaskRecord, error) {
|
||||
if err := taskActor(ctx, s.DB, domain, actor, false); err != nil {
|
||||
func (s *Store) GetTask(ctx context.Context, domain, actor, id string) (result TaskRecord, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("task repository", resultErr) }()
|
||||
if err := s.taskActor(ctx, s.DB, domain, actor, false); err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
var data, hash string
|
||||
err := s.DB.QueryRowContext(ctx, `SELECT data,document_hash FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND uuid=?`, domain, actor, id).Scan(&data, &hash)
|
||||
err := s.DB.QueryRowContext(ctx, `SELECT data,document_hash FROM organizer_items WHERE domain_uuid=`+s.sqlParam(1)+` AND owner_uuid=`+s.sqlParam(2)+` AND uuid=`+s.sqlParam(3)+``, domain, actor, id).Scan(&data, &hash)
|
||||
if err != nil {
|
||||
return TaskRecord{}, err
|
||||
}
|
||||
@@ -419,8 +439,9 @@ func (s *Store) GetTask(ctx context.Context, domain, actor, id string) (TaskReco
|
||||
return item, err
|
||||
}
|
||||
|
||||
func (s *Store) ListTasks(ctx context.Context, domain, actor string, query TaskQuery) ([]TaskRecord, string, error) {
|
||||
if err := taskActor(ctx, s.DB, domain, actor, false); err != nil {
|
||||
func (s *Store) ListTasks(ctx context.Context, domain, actor string, query TaskQuery) (result []TaskRecord, cursor string, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("task repository", resultErr) }()
|
||||
if err := s.taskActor(ctx, s.DB, domain, actor, false); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
if query.Kind != "task" && query.Kind != "project" {
|
||||
@@ -433,26 +454,26 @@ func (s *Store) ListTasks(ctx context.Context, domain, actor string, query TaskQ
|
||||
query.Limit = 60
|
||||
}
|
||||
index := query.View == "index"
|
||||
if index && (query.Kind != "task" || query.Hierarchy || taskIndexOrder(query.Sort) == "" || (query.Order != "" && query.Order != "asc" && query.Order != "desc")) {
|
||||
if index && (query.Kind != "task" || query.Hierarchy || s.taskIndexOrder(query.Sort) == "" || (query.Order != "" && query.Order != "asc" && query.Order != "desc")) {
|
||||
return nil, "", ErrTaskInvalid
|
||||
}
|
||||
if !index && (query.Filter != "" || query.Sort != "" || query.Order != "") {
|
||||
return nil, "", ErrTaskInvalid
|
||||
}
|
||||
q := `SELECT data FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND kind=?`
|
||||
q := `SELECT data FROM organizer_items WHERE domain_uuid=` + s.sqlParam(1) + ` AND owner_uuid=` + s.sqlParam(2) + ` AND kind=` + s.sqlParam(3) + ``
|
||||
args := []any{domain, actor, query.Kind}
|
||||
hierarchy := query.Hierarchy && query.Kind == "task" && query.View != "family"
|
||||
if hierarchy {
|
||||
q = `WITH task_rows AS (
|
||||
SELECT i.*,COALESCE(p.created_at_ms,i.created_at_ms) AS family_created,
|
||||
COALESCE(p.uuid,i.uuid) AS family_uuid,(i.parent_uuid='') AS family_head
|
||||
COALESCE(p.uuid,i.uuid) AS family_uuid,CASE WHEN i.parent_uuid='' THEN 1 ELSE 0 END AS family_head
|
||||
FROM organizer_items i LEFT JOIN organizer_items p
|
||||
ON p.domain_uuid=i.domain_uuid AND p.owner_uuid=i.owner_uuid AND p.uuid=i.parent_uuid
|
||||
WHERE i.domain_uuid=? AND i.owner_uuid=?
|
||||
) SELECT data FROM task_rows WHERE kind=?`
|
||||
WHERE i.domain_uuid=` + s.sqlParam(1) + ` AND i.owner_uuid=` + s.sqlParam(2) + `
|
||||
) SELECT data FROM task_rows WHERE kind=` + s.sqlParam(3) + ``
|
||||
}
|
||||
if index {
|
||||
filter, values, err := taskIndexFilter(query.Filter, query.Today)
|
||||
filter, values, err := s.taskIndexFilter(query.Filter, query.Today, len(args))
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@@ -471,11 +492,11 @@ func (s *Store) ListTasks(ctx context.Context, domain, actor string, query TaskQ
|
||||
if _, err := s.GetTask(ctx, domain, actor, query.Parent); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
q += ` AND parent_uuid=?`
|
||||
q += ` AND parent_uuid=` + s.sqlParam(len(args)+1) + ``
|
||||
args = append(args, query.Parent)
|
||||
}
|
||||
if query.Project != "" {
|
||||
q += ` AND project_uuid=?`
|
||||
q += ` AND project_uuid=` + s.sqlParam(len(args)+1) + ``
|
||||
project := query.Project
|
||||
if index && project == "none" {
|
||||
project = ""
|
||||
@@ -485,21 +506,21 @@ func (s *Store) ListTasks(ctx context.Context, domain, actor string, query TaskQ
|
||||
if query.Kind == "task" {
|
||||
switch query.View {
|
||||
case "today":
|
||||
q += ` AND status NOT IN ('done','cancelled') AND (planned_on=? OR (due_on!='' AND due_on<=?))`
|
||||
q += ` AND status NOT IN ('done','cancelled') AND (planned_on=` + s.sqlParam(len(args)+1) + ` OR (due_on!='' AND due_on<=` + s.sqlParam(len(args)+2) + `))`
|
||||
args = append(args, query.Today, query.Today)
|
||||
case "day":
|
||||
q += ` AND status NOT IN ('done','cancelled') AND (planned_on=? OR due_on=?)`
|
||||
q += ` AND status NOT IN ('done','cancelled') AND (planned_on=` + s.sqlParam(len(args)+1) + ` OR due_on=` + s.sqlParam(len(args)+2) + `)`
|
||||
args = append(args, query.Today, query.Today)
|
||||
case "carryover":
|
||||
q += ` AND status NOT IN ('done','cancelled') AND ((planned_on!='' AND planned_on<?) OR (due_on!='' AND due_on<?))`
|
||||
q += ` AND status NOT IN ('done','cancelled') AND ((planned_on!='' AND planned_on<` + s.sqlParam(len(args)+1) + `) OR (due_on!='' AND due_on<` + s.sqlParam(len(args)+2) + `))`
|
||||
args = append(args, query.Today, query.Today)
|
||||
case "inbox", "backlog", "someday":
|
||||
q += ` AND status NOT IN ('done','cancelled') AND bucket=?`
|
||||
q += ` AND status NOT IN ('done','cancelled') AND bucket=` + s.sqlParam(len(args)+1) + ``
|
||||
args = append(args, query.View)
|
||||
case "done":
|
||||
q += ` AND status IN ('done','cancelled')`
|
||||
case "review":
|
||||
q += ` AND status NOT IN ('done','cancelled') AND ((review_on!='' AND review_on<=?) OR updated_at_ms<?)`
|
||||
q += ` AND status NOT IN ('done','cancelled') AND ((review_on!='' AND review_on<=` + s.sqlParam(len(args)+1) + `) OR updated_at_ms<` + s.sqlParam(len(args)+2) + `)`
|
||||
args = append(args, query.Today, time.Now().AddDate(0, 0, -30).UnixMilli())
|
||||
case "all":
|
||||
q += ` AND status NOT IN ('done','cancelled')`
|
||||
@@ -510,7 +531,7 @@ func (s *Store) ListTasks(ctx context.Context, domain, actor string, query TaskQ
|
||||
}
|
||||
}
|
||||
if query.Search != "" {
|
||||
q += ` AND instr(lower(title),lower(?))>0`
|
||||
q += " AND " + s.taskTitleContains(s.sqlParam(len(args)+1))
|
||||
args = append(args, query.Search)
|
||||
}
|
||||
if query.Before != "" {
|
||||
@@ -519,8 +540,8 @@ func (s *Store) ListTasks(ctx context.Context, domain, actor string, query TaskQ
|
||||
if query.Order == "desc" {
|
||||
comparison = "<"
|
||||
}
|
||||
key := taskIndexOrder(query.Sort)
|
||||
q += " AND (" + key + ",uuid)" + comparison + "(SELECT " + key + ",uuid FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND kind='task' AND uuid=?)"
|
||||
key := s.taskIndexOrder(query.Sort)
|
||||
q += " AND (" + key + ",uuid)" + comparison + "(SELECT " + key + ",uuid FROM organizer_items WHERE domain_uuid=" + s.sqlParam(len(args)+1) + " AND owner_uuid=" + s.sqlParam(len(args)+2) + " AND kind='task' AND uuid=" + s.sqlParam(len(args)+3) + ")"
|
||||
args = append(args, domain, actor, query.Before)
|
||||
} else if hierarchy {
|
||||
// A separate indexed cursor lookup keeps the wide task_rows CTE
|
||||
@@ -528,19 +549,19 @@ func (s *Store) ListTasks(ctx context.Context, domain, actor string, query TaskQ
|
||||
var familyCreated, created int64
|
||||
var familyUUID, id string
|
||||
var head int
|
||||
err := s.DB.QueryRowContext(ctx, `SELECT COALESCE(p.created_at_ms,i.created_at_ms),COALESCE(p.uuid,i.uuid),(i.parent_uuid=''),i.created_at_ms,i.uuid
|
||||
err := s.DB.QueryRowContext(ctx, `SELECT COALESCE(p.created_at_ms,i.created_at_ms),COALESCE(p.uuid,i.uuid),CASE WHEN i.parent_uuid='' THEN 1 ELSE 0 END,i.created_at_ms,i.uuid
|
||||
FROM organizer_items i LEFT JOIN organizer_items p ON p.domain_uuid=i.domain_uuid AND p.owner_uuid=i.owner_uuid AND p.uuid=i.parent_uuid
|
||||
WHERE i.domain_uuid=? AND i.owner_uuid=? AND i.uuid=?`, domain, actor, query.Before).Scan(&familyCreated, &familyUUID, &head, &created, &id)
|
||||
WHERE i.domain_uuid=`+s.sqlParam(1)+` AND i.owner_uuid=`+s.sqlParam(2)+` AND i.uuid=`+s.sqlParam(3)+``, domain, actor, query.Before).Scan(&familyCreated, &familyUUID, &head, &created, &id)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return []TaskRecord{}, "", nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
q += ` AND (family_created,family_uuid,family_head,created_at_ms,uuid)<(?,?,?,?,?)`
|
||||
q += ` AND (family_created,family_uuid,family_head,created_at_ms,uuid)<(` + s.sqlParam(len(args)+1) + `,` + s.sqlParam(len(args)+2) + `,` + s.sqlParam(len(args)+3) + `,` + s.sqlParam(len(args)+4) + `,` + s.sqlParam(len(args)+5) + `)`
|
||||
args = append(args, familyCreated, familyUUID, head, created, id)
|
||||
} else {
|
||||
q += ` AND (created_at_ms,uuid)<(SELECT created_at_ms,uuid FROM organizer_items WHERE domain_uuid=? AND owner_uuid=? AND uuid=?)`
|
||||
q += ` AND (created_at_ms,uuid)<(SELECT created_at_ms,uuid FROM organizer_items WHERE domain_uuid=` + s.sqlParam(len(args)+1) + ` AND owner_uuid=` + s.sqlParam(len(args)+2) + ` AND uuid=` + s.sqlParam(len(args)+3) + `)`
|
||||
args = append(args, domain, actor, query.Before)
|
||||
}
|
||||
}
|
||||
@@ -549,11 +570,11 @@ func (s *Store) ListTasks(ctx context.Context, domain, actor string, query TaskQ
|
||||
if query.Order == "desc" {
|
||||
direction = "DESC"
|
||||
}
|
||||
q += " ORDER BY " + taskIndexOrder(query.Sort) + " " + direction + ",uuid " + direction + " LIMIT ?"
|
||||
q += " ORDER BY " + s.taskIndexOrder(query.Sort) + " " + direction + ",uuid " + direction + " LIMIT " + s.sqlParam(len(args)+1)
|
||||
} else if hierarchy {
|
||||
q += ` ORDER BY family_created DESC,family_uuid DESC,family_head DESC,created_at_ms DESC,uuid DESC LIMIT ?`
|
||||
q += ` ORDER BY family_created DESC,family_uuid DESC,family_head DESC,created_at_ms DESC,uuid DESC LIMIT ` + s.sqlParam(len(args)+1) + ``
|
||||
} else {
|
||||
q += ` ORDER BY created_at_ms DESC,uuid DESC LIMIT ?`
|
||||
q += ` ORDER BY created_at_ms DESC,uuid DESC LIMIT ` + s.sqlParam(len(args)+1) + ``
|
||||
}
|
||||
args = append(args, query.Limit+1)
|
||||
rows, err := s.DB.QueryContext(ctx, q, args...)
|
||||
@@ -591,11 +612,12 @@ type TaskRevision struct {
|
||||
CreatedMS int64 `json:"created_at_ms"`
|
||||
}
|
||||
|
||||
func (s *Store) TaskHistory(ctx context.Context, domain, actor, id string) ([]TaskRevision, error) {
|
||||
func (s *Store) TaskHistory(ctx context.Context, domain, actor, id string) (result []TaskRevision, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("task repository", resultErr) }()
|
||||
if _, err := s.GetTask(ctx, domain, actor, id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT version,created_at_ms FROM organizer_revisions WHERE domain_uuid=? AND item_uuid=? ORDER BY version DESC LIMIT 50`, domain, id)
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT version,created_at_ms FROM organizer_revisions WHERE domain_uuid=`+s.sqlParam(1)+` AND item_uuid=`+s.sqlParam(2)+` ORDER BY version DESC LIMIT 50`, domain, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user