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
@@ -3,6 +3,7 @@ package store
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Subscriptions are trusted worker configuration, never request parameters.
|
||||
@@ -67,7 +68,10 @@ func (s *Store) ensureActivitySubscriptions() error {
|
||||
|
||||
// PendingActivityConsumerDomains does not scan event history or rely on the
|
||||
// legacy shared status. Acknowledgment by another consumer cannot hide work.
|
||||
func (s *Store) PendingActivityConsumerDomains(ctx context.Context, sub ActivitySubscription, limit int) ([]string, error) {
|
||||
func (s *Store) PendingActivityConsumerDomains(ctx context.Context, sub ActivitySubscription, limit int) (_ []string, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("activity subscriber domains", resultErr) }()
|
||||
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
||||
defer cancel()
|
||||
marks, args, err := sub.filter()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -77,7 +81,14 @@ func (s *Store) PendingActivityConsumerDomains(ctx context.Context, sub Activity
|
||||
}
|
||||
args = append([]any{sub.ConsumerID}, args...)
|
||||
args = append(args, limit)
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT h.domain_uuid FROM activity_outbox_heads h LEFT JOIN activity_outbox_checkpoints c ON c.domain_uuid=h.domain_uuid AND c.consumer_id=? WHERE h.event_type IN (`+marks+`) AND h.last_sequence>COALESCE(c.last_sequence,0) GROUP BY h.domain_uuid ORDER BY COALESCE(c.updated_at_ms,0),h.domain_uuid LIMIT ?`, args...)
|
||||
if s.sqlBackend == storePostgreSQL {
|
||||
params := make([]string, len(sub.EventTypes))
|
||||
for i := range params {
|
||||
params[i] = s.sqlParam(i + 2)
|
||||
}
|
||||
marks = strings.Join(params, ",")
|
||||
}
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT h.domain_uuid FROM activity_outbox_heads h LEFT JOIN activity_outbox_checkpoints c ON c.domain_uuid=h.domain_uuid AND c.consumer_id=`+s.sqlParam(1)+` WHERE h.event_type IN (`+marks+`) AND h.last_sequence>COALESCE(c.last_sequence,0) GROUP BY h.domain_uuid ORDER BY MIN(COALESCE(c.updated_at_ms,0)),h.domain_uuid LIMIT `+s.sqlParam(len(args)), args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -95,7 +106,10 @@ func (s *Store) PendingActivityConsumerDomains(ctx context.Context, sub Activity
|
||||
|
||||
// The SQL limit is applied per type first, so unrelated floods and SQLite's
|
||||
// final multi-type ordering cannot materialize an unbounded pending backlog.
|
||||
func (s *Store) ActivityOutboxForConsumer(ctx context.Context, sub ActivitySubscription, domain string, limit int) ([]ActivityOutboxRecord, error) {
|
||||
func (s *Store) ActivityOutboxForConsumer(ctx context.Context, sub ActivitySubscription, domain string, limit int) (_ []ActivityOutboxRecord, resultErr error) {
|
||||
defer func() { resultErr = s.sqlError("activity subscriber history", resultErr) }()
|
||||
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
|
||||
defer cancel()
|
||||
_, _, err := sub.filter()
|
||||
if err != nil || domain == "" {
|
||||
return nil, ErrActivityOutboxInput
|
||||
@@ -106,11 +120,12 @@ func (s *Store) ActivityOutboxForConsumer(ctx context.Context, sub ActivitySubsc
|
||||
queries := []string{}
|
||||
args := []any{}
|
||||
for _, typ := range sub.EventTypes {
|
||||
queries = append(queries, `SELECT * FROM (SELECT `+activityOutboxColumns+` FROM activity_outbox WHERE domain_uuid=? AND event_type=? AND sequence>COALESCE((SELECT last_sequence FROM activity_outbox_checkpoints WHERE consumer_id=? AND domain_uuid=?),0) ORDER BY sequence LIMIT ?)`)
|
||||
i := len(args)
|
||||
queries = append(queries, `SELECT * FROM (SELECT `+activityOutboxColumns+` FROM activity_outbox WHERE domain_uuid=`+s.sqlParam(i+1)+` AND event_type=`+s.sqlParam(i+2)+` AND sequence>COALESCE((SELECT last_sequence FROM activity_outbox_checkpoints WHERE consumer_id=`+s.sqlParam(i+3)+` AND domain_uuid=`+s.sqlParam(i+4)+`),0) ORDER BY sequence LIMIT `+s.sqlParam(i+5)+`) AS typed_events`)
|
||||
args = append(args, domain, typ, sub.ConsumerID, domain, limit)
|
||||
}
|
||||
args = append(args, limit)
|
||||
rows, err := s.DB.QueryContext(ctx, strings.Join(queries, " UNION ")+` ORDER BY sequence LIMIT ?`, args...)
|
||||
rows, err := s.DB.QueryContext(ctx, strings.Join(queries, " UNION ")+` ORDER BY sequence LIMIT `+s.sqlParam(len(args)), args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user