refactor(db): split revision preview from meta_json
Preview BIRD-фрагменты в config_revision_preview; meta_json только счётчик префиксов. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -687,7 +687,7 @@ func (p *Postgres) GetRevision(tenantID, revisionID string) (*store.Revision, er
|
||||
if mj.PreviewFragments == nil {
|
||||
mj.PreviewFragments = map[string]string{}
|
||||
}
|
||||
r.PreviewFragments = mj.PreviewFragments
|
||||
r.PreviewFragments = loadRevisionPreview(ctx, p.pool, revisionID, mj.PreviewFragments)
|
||||
r.MaterializedPrefixCount = mj.MaterializedPrefixCount
|
||||
return &r, nil
|
||||
}
|
||||
@@ -848,26 +848,39 @@ func (p *Postgres) CreateRollbackRevision(tenantID, sourceRevisionID string) (st
|
||||
ctx := context.Background()
|
||||
newID := uuid.NewString()
|
||||
parent := sourceRevisionID
|
||||
meta, _ := json.Marshal(map[string]any{
|
||||
"preview_fragments": src.PreviewFragments,
|
||||
"materialized_prefix_count": src.MaterializedPrefixCount,
|
||||
})
|
||||
meta, err := revisionMetaWithoutPreview(src.MaterializedPrefixCount)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var modArg any
|
||||
if strings.TrimSpace(src.ModuleID) != "" {
|
||||
modArg = src.ModuleID
|
||||
}
|
||||
_, err = p.pool.Exec(ctx, `
|
||||
INSERT INTO config_revision (id, tenant_id, module_id, content_hash, parent_revision_id, meta_json)
|
||||
VALUES ($1,$2,$3,$4,$5::uuid,$6::jsonb)`,
|
||||
newID, tenantID, modArg, src.ContentHash+":rollback", parent, string(meta))
|
||||
tx, err := p.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// copy materialized prefixes
|
||||
_, _ = p.pool.Exec(ctx, `
|
||||
defer func() { _ = tx.Rollback(ctx) }()
|
||||
_, err = tx.Exec(ctx, `
|
||||
INSERT INTO config_revision (id, tenant_id, module_id, content_hash, parent_revision_id, meta_json)
|
||||
VALUES ($1,$2,$3,$4,$5::uuid,$6::jsonb)`,
|
||||
newID, tenantID, modArg, src.ContentHash+":rollback", parent, meta)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := copyRevisionPreview(ctx, tx, newID, sourceRevisionID); err != nil {
|
||||
return "", err
|
||||
}
|
||||
_, err = tx.Exec(ctx, `
|
||||
INSERT INTO revision_materialized_prefix (revision_id, prefix, community_id, source, meta_json)
|
||||
SELECT $1::uuid, prefix, community_id, source, meta_json FROM revision_materialized_prefix WHERE revision_id=$2::uuid`,
|
||||
newID, sourceRevisionID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := tx.Commit(ctx); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return newID, nil
|
||||
}
|
||||
|
||||
@@ -1056,10 +1069,7 @@ func (p *Postgres) CreateRenderRevision(revisionID, tenantID, moduleID string, p
|
||||
if previewFragments == nil {
|
||||
previewFragments = map[string]string{}
|
||||
}
|
||||
meta, err := json.Marshal(map[string]any{
|
||||
"preview_fragments": previewFragments,
|
||||
"materialized_prefix_count": len(prefixes),
|
||||
})
|
||||
meta, err := revisionMetaWithoutPreview(len(prefixes))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1073,13 +1083,17 @@ func (p *Postgres) CreateRenderRevision(revisionID, tenantID, moduleID string, p
|
||||
if parentRevisionID != nil && strings.TrimSpace(*parentRevisionID) != "" {
|
||||
parent = strings.TrimSpace(*parentRevisionID)
|
||||
}
|
||||
revID := strings.TrimSpace(revisionID)
|
||||
_, err = tx.Exec(ctx, `
|
||||
INSERT INTO config_revision (id, tenant_id, module_id, content_hash, parent_revision_id, meta_json)
|
||||
VALUES ($1::uuid, $2::uuid, $3::uuid, $4, $5::uuid, $6::jsonb)`,
|
||||
strings.TrimSpace(revisionID), tenantID, moduleID, strings.TrimSpace(contentHash), parent, string(meta))
|
||||
revID, tenantID, moduleID, strings.TrimSpace(contentHash), parent, meta)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := insertRevisionPreview(ctx, tx, revID, previewFragments); err != nil {
|
||||
return err
|
||||
}
|
||||
if len(prefixes) > 0 {
|
||||
_, err = tx.CopyFrom(ctx,
|
||||
pgx.Identifier{"revision_materialized_prefix"},
|
||||
@@ -1094,7 +1108,7 @@ func (p *Postgres) CreateRenderRevision(revisionID, tenantID, moduleID string, p
|
||||
if strings.TrimSpace(src) == "" {
|
||||
src = "render"
|
||||
}
|
||||
return []any{strings.TrimSpace(revisionID), strings.TrimSpace(pr.Prefix), comm, src}, nil
|
||||
return []any{revID, strings.TrimSpace(pr.Prefix), comm, src}, nil
|
||||
}))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user