refactor(store,tools): migrate IDs from UUID to bigserial int64
Some checks failed
CI / build-and-test (push) Failing after -31m12s
Some checks failed
CI / build-and-test (push) Failing after -31m12s
All internal entity lookups now use bigserial primary keys (int64) while GUIDs are retained for external/public identification. Updated store functions (TouchProject, UpdateThoughtMetadata, AddThoughtAttachment) to query by id instead of guid, added GetThoughtByID, changed semanticSearch and all tool helpers to use *int64 project IDs, and updated retry/backfill workers to use int64 thought IDs throughout.
This commit is contained in:
@@ -2,11 +2,11 @@ package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/modelcontextprotocol/go-sdk/mcp"
|
||||
"golang.org/x/sync/semaphore"
|
||||
|
||||
@@ -37,18 +37,18 @@ type RetryMetadataTool struct {
|
||||
|
||||
type RetryLocker struct {
|
||||
mu sync.Mutex
|
||||
locks map[uuid.UUID]time.Time
|
||||
locks map[int64]time.Time
|
||||
}
|
||||
|
||||
func NewRetryLocker() *RetryLocker {
|
||||
return &RetryLocker{locks: map[uuid.UUID]time.Time{}}
|
||||
return &RetryLocker{locks: map[int64]time.Time{}}
|
||||
}
|
||||
|
||||
func (l *RetryLocker) Acquire(id uuid.UUID, ttl time.Duration) bool {
|
||||
func (l *RetryLocker) Acquire(id int64, ttl time.Duration) bool {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
if l.locks == nil {
|
||||
l.locks = map[uuid.UUID]time.Time{}
|
||||
l.locks = map[int64]time.Time{}
|
||||
}
|
||||
now := time.Now()
|
||||
if exp, ok := l.locks[id]; ok && exp.After(now) {
|
||||
@@ -58,7 +58,7 @@ func (l *RetryLocker) Acquire(id uuid.UUID, ttl time.Duration) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (l *RetryLocker) Release(id uuid.UUID) {
|
||||
func (l *RetryLocker) Release(id int64) {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
delete(l.locks, id)
|
||||
@@ -111,23 +111,24 @@ func (t *RetryMetadataTool) Handle(ctx context.Context, req *mcp.CallToolRequest
|
||||
return t.retryer.Handle(ctx, req, in)
|
||||
}
|
||||
|
||||
func (r *MetadataRetryer) QueueThought(id uuid.UUID) {
|
||||
func (r *MetadataRetryer) QueueThought(id int64) {
|
||||
go func() {
|
||||
started := time.Now()
|
||||
idStr := fmt.Sprint(id)
|
||||
if !r.lock.Acquire(id, 15*time.Minute) {
|
||||
return
|
||||
}
|
||||
defer r.lock.Release(id)
|
||||
|
||||
r.logger.Info("background metadata started",
|
||||
slog.String("thought_id", id.String()),
|
||||
slog.String("thought_id", idStr),
|
||||
slog.String("provider", r.metadata.PrimaryProvider()),
|
||||
slog.String("model", r.metadata.PrimaryModel()),
|
||||
)
|
||||
updated, err := r.retryOne(r.backgroundCtx, id)
|
||||
if err != nil {
|
||||
r.logger.Warn("background metadata error",
|
||||
slog.String("thought_id", id.String()),
|
||||
slog.String("thought_id", idStr),
|
||||
slog.String("provider", r.metadata.PrimaryProvider()),
|
||||
slog.String("model", r.metadata.PrimaryModel()),
|
||||
slog.Duration("duration", time.Since(started)),
|
||||
@@ -136,7 +137,7 @@ func (r *MetadataRetryer) QueueThought(id uuid.UUID) {
|
||||
return
|
||||
}
|
||||
r.logger.Info("background metadata complete",
|
||||
slog.String("thought_id", id.String()),
|
||||
slog.String("thought_id", idStr),
|
||||
slog.String("provider", r.metadata.PrimaryProvider()),
|
||||
slog.String("model", r.metadata.PrimaryModel()),
|
||||
slog.Bool("updated", updated),
|
||||
@@ -156,9 +157,9 @@ func (r *MetadataRetryer) Handle(ctx context.Context, req *mcp.CallToolRequest,
|
||||
return nil, RetryMetadataOutput{}, err
|
||||
}
|
||||
|
||||
var projectID *uuid.UUID
|
||||
var projectID *int64
|
||||
if project != nil {
|
||||
projectID = &project.ID
|
||||
projectID = &project.NumericID
|
||||
}
|
||||
|
||||
thoughts, err := r.store.ListThoughtsPendingMetadataRetry(ctx, limit, projectID, in.IncludeArchived, in.OlderThanDays)
|
||||
@@ -205,7 +206,7 @@ func (r *MetadataRetryer) Handle(ctx context.Context, req *mcp.CallToolRequest,
|
||||
r.lock.Release(thought.ID)
|
||||
if err != nil {
|
||||
mu.Lock()
|
||||
out.Failures = append(out.Failures, RetryMetadataFailure{ID: thought.ID.String(), Error: err.Error()})
|
||||
out.Failures = append(out.Failures, RetryMetadataFailure{ID: fmt.Sprint(thought.ID), Error: err.Error()})
|
||||
mu.Unlock()
|
||||
return
|
||||
}
|
||||
@@ -228,8 +229,8 @@ func (r *MetadataRetryer) Handle(ctx context.Context, req *mcp.CallToolRequest,
|
||||
return nil, out, nil
|
||||
}
|
||||
|
||||
func (r *MetadataRetryer) retryOne(ctx context.Context, id uuid.UUID) (bool, error) {
|
||||
thought, err := r.store.GetThought(ctx, id)
|
||||
func (r *MetadataRetryer) retryOne(ctx context.Context, id int64) (bool, error) {
|
||||
thought, err := r.store.GetThoughtByID(ctx, id)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user