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
@@ -2,11 +2,12 @@ package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"pageswiki/internal/db"
|
||||
)
|
||||
|
||||
const ObjectListCandidateLimit = 400
|
||||
@@ -28,6 +29,12 @@ type objectListCursor struct {
|
||||
}
|
||||
|
||||
func (s *Store) EnsureObjectListingSchema() error {
|
||||
if s.sqlBackend == storePostgreSQL {
|
||||
return db.ApplyPostgreSQLMigrations(context.Background(), s.DB, "store-object-listing", []db.PostgreSQLMigration{{Version: 1, Name: "metadata listing indexes", Statements: []string{
|
||||
`CREATE INDEX idx_objects_metadata_page ON objects(COALESCE(created_at,0) DESC,uuid ASC)`,
|
||||
`CREATE INDEX idx_paths_object_domain_page ON paths(object_uuid,domain_uuid,path)`,
|
||||
}, Assertions: []string{`SELECT uuid,kind,created_at FROM objects WHERE 1=0`, `SELECT domain_uuid,path,object_uuid FROM paths WHERE 1=0`}}})
|
||||
}
|
||||
var available bool
|
||||
if err := s.DB.QueryRow(`SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name='objects') AND EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name='paths')`).Scan(&available); err != nil {
|
||||
return err
|
||||
@@ -74,11 +81,11 @@ func (s *Store) DecodeObjectListCursor(encoded, domain, principal string) (*Obje
|
||||
func (s *Store) LoadObjectListReadGrants(ctx context.Context, domain, principal string) (map[string]bool, bool, error) {
|
||||
exact := make(map[string]bool)
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT g.target_type,g.target_id FROM principals p
|
||||
JOIN domain_memberships m ON m.principal_uuid=p.uuid AND m.domain_uuid=? AND m.state='active'
|
||||
JOIN domain_memberships m ON m.principal_uuid=p.uuid AND m.domain_uuid=`+s.sqlParam(1)+` AND m.state='active'
|
||||
JOIN auth_role_bindings b ON b.membership_uuid=m.uuid
|
||||
JOIN auth_roles r ON r.uuid=b.role_uuid AND r.domain_uuid=m.domain_uuid
|
||||
JOIN auth_capability_grants g ON g.role_uuid=r.uuid AND g.capability='read'
|
||||
WHERE p.uuid=? AND p.state IN ('active','readonly') AND g.target_type IN ('domain','object') LIMIT 4097`, domain, principal)
|
||||
WHERE p.uuid=`+s.sqlParam(2)+` AND p.state IN ('active','readonly') AND g.target_type IN ('domain','object') LIMIT 4097`, domain, principal)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
@@ -112,7 +119,7 @@ func (s *Store) ListObjectMetadataPage(ctx context.Context, domain string, after
|
||||
if !broad && allowedPath == nil {
|
||||
return nil, nil, ErrAccessDenied
|
||||
}
|
||||
tx, err := s.DB.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})
|
||||
tx, err := s.DB.BeginTx(ctx, s.policyReadOptions())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -127,8 +134,8 @@ func (s *Store) ListObjectMetadataPage(ctx context.Context, domain string, after
|
||||
// UUID within large same-second import batches instead of re-scanning
|
||||
// every earlier UUID in that timestamp on each page.
|
||||
branches = []branch{
|
||||
{` AND COALESCE(o.created_at,0)=? AND o.uuid>?`, []any{domain, after.CreatedAt, after.UUID}},
|
||||
{` AND COALESCE(o.created_at,0)<?`, []any{domain, after.CreatedAt}},
|
||||
{` AND COALESCE(o.created_at,0)=` + s.sqlParam(2) + ` AND o.uuid>` + s.sqlParam(3), []any{domain, after.CreatedAt, after.UUID}},
|
||||
{` AND COALESCE(o.created_at,0)<` + s.sqlParam(2), []any{domain, after.CreatedAt}},
|
||||
}
|
||||
}
|
||||
candidates := make([]Object, 0, ObjectListCandidateLimit+1)
|
||||
@@ -138,7 +145,7 @@ func (s *Store) ListObjectMetadataPage(ctx context.Context, domain string, after
|
||||
break
|
||||
}
|
||||
rows, err := tx.QueryContext(ctx, `SELECT o.uuid,COALESCE(o.kind,''),COALESCE(o.created_at,0) FROM objects o
|
||||
WHERE EXISTS(SELECT 1 FROM paths p WHERE p.domain_uuid=? AND p.object_uuid=o.uuid)`+part.predicate+` ORDER BY COALESCE(o.created_at,0) DESC,o.uuid ASC LIMIT ?`, append(part.args, remaining)...)
|
||||
WHERE EXISTS(SELECT 1 FROM paths p WHERE p.domain_uuid=`+s.sqlParam(1)+` AND p.object_uuid=o.uuid)`+part.predicate+` ORDER BY COALESCE(o.created_at,0) DESC,o.uuid ASC LIMIT `+s.sqlParam(len(part.args)+1), append(part.args, remaining)...)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -170,7 +177,11 @@ func (s *Store) ListObjectMetadataPage(ctx context.Context, domain string, after
|
||||
}
|
||||
}
|
||||
if len(args) > 1 {
|
||||
rows, err := tx.QueryContext(ctx, `SELECT object_uuid,path FROM paths WHERE domain_uuid=? AND object_uuid IN (`+strings.TrimRight(strings.Repeat("?,", len(args)-1), ",")+`) LIMIT 8001`, args...)
|
||||
params := make([]string, len(args)-1)
|
||||
for i := range params {
|
||||
params[i] = s.sqlParam(i + 2)
|
||||
}
|
||||
rows, err := tx.QueryContext(ctx, `SELECT object_uuid,path FROM paths WHERE domain_uuid=`+s.sqlParam(1)+` AND object_uuid IN (`+strings.Join(params, ",")+`) LIMIT 8001`, args...)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user