Build publication report indexes once
This commit is contained in:
@@ -282,6 +282,12 @@ Refactoring opportunity:
|
|||||||
|
|
||||||
## 7. P3: Build publication-report lookup tables once
|
## 7. P3: Build publication-report lookup tables once
|
||||||
|
|
||||||
|
Status: Completed. Publication reports build configured/extraction lookup tables
|
||||||
|
and a first-declaration-per-source commit index once. Local lookup work is now
|
||||||
|
`O(A log A + X log X + K + R)` plus copied entry payloads. Removed the unused
|
||||||
|
destination-display helper. Status, remote artifact inspection, exact carried-key,
|
||||||
|
partial-failure, and catalog-evidence tests pass.
|
||||||
|
|
||||||
Stage: 12.
|
Stage: 12.
|
||||||
|
|
||||||
Locations: `internal/app/session_state_command.go:256–270`,
|
Locations: `internal/app/session_state_command.go:256–270`,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package app
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||||
@@ -76,32 +75,20 @@ func isPublishOutputOutcome(status string) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func committedPublishedOutput(commit *artifacts.RemoteCommitManifest, source string) (artifacts.RemoteArtifact, bool) {
|
func committedPublishedOutputs(commit *artifacts.RemoteCommitManifest) map[string]artifacts.RemoteArtifact {
|
||||||
|
out := map[string]artifacts.RemoteArtifact{}
|
||||||
if commit == nil {
|
if commit == nil {
|
||||||
return artifacts.RemoteArtifact{}, false
|
return out
|
||||||
}
|
}
|
||||||
for _, artifact := range commit.Artifacts {
|
for _, artifact := range commit.Artifacts {
|
||||||
if artifact.Type == artifacts.RemoteArtifactTypePublishedOutput && artifact.Source == source {
|
if artifact.Type != artifacts.RemoteArtifactTypePublishedOutput {
|
||||||
return artifact, true
|
continue
|
||||||
|
}
|
||||||
|
if _, exists := out[artifact.Source]; !exists {
|
||||||
|
out[artifact.Source] = artifact
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return artifacts.RemoteArtifact{}, false
|
return out
|
||||||
}
|
|
||||||
|
|
||||||
func helperPublishedOutputDest(rule config.PublishOutputRule, catalog *artifacts.ArtifactCatalog) (string, bool, error) {
|
|
||||||
source := strings.TrimSpace(rule.Source)
|
|
||||||
normalized, err := artifactpolicy.ResolvePublishedDestinationWithExtractions(
|
|
||||||
source,
|
|
||||||
rule.Dest,
|
|
||||||
helperConfiguredOutputPathMap(catalog),
|
|
||||||
helperExtractionOutputSet(catalog),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return "", false, err
|
|
||||||
}
|
|
||||||
entry, ok := catalog.Lookup(source)
|
|
||||||
showDest := !ok || strings.TrimSpace(entry.CanonicalRelPath) != normalized
|
|
||||||
return normalized, showDest, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func helperExtractionOutputSet(catalog *artifacts.ArtifactCatalog) map[string]struct{} {
|
func helperExtractionOutputSet(catalog *artifacts.ArtifactCatalog) map[string]struct{} {
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||||
@@ -246,15 +248,20 @@ func builtinArtifactInspectionState(local *manifest.Manifest, entry artifacts.Ca
|
|||||||
}
|
}
|
||||||
|
|
||||||
func inspectPublishedOutputs(ctx context.Context, cfg *config.Config, store storage.ObjectStore, catalog *artifacts.ArtifactCatalog, current *RemoteCurrentState, locks []artifacts.RemoteLock, locksKnown bool, remoteState string) ([]sessionPublishedOutput, error) {
|
func inspectPublishedOutputs(ctx context.Context, cfg *config.Config, store storage.ObjectStore, catalog *artifacts.ArtifactCatalog, current *RemoteCurrentState, locks []artifacts.RemoteLock, locksKnown bool, remoteState string) ([]sessionPublishedOutput, error) {
|
||||||
outputs := make([]sessionPublishedOutput, 0, len(cfg.PublicationOutputs()))
|
rules := cfg.PublicationOutputs()
|
||||||
|
outputs := make([]sessionPublishedOutput, 0, len(rules))
|
||||||
locked := remoteLockSourceSet(locks)
|
locked := remoteLockSourceSet(locks)
|
||||||
|
configuredOutputs := helperConfiguredOutputPathMap(catalog)
|
||||||
|
extractionOutputs := helperExtractionOutputSet(catalog)
|
||||||
|
var declarations map[string]artifacts.RemoteArtifact
|
||||||
outcomes := map[string]string{}
|
outcomes := map[string]string{}
|
||||||
if current != nil {
|
if current != nil {
|
||||||
outcomes = committedPublishOutputOutcomes(current.Manifest)
|
outcomes = committedPublishOutputOutcomes(current.Manifest)
|
||||||
|
declarations = committedPublishedOutputs(current.Commit)
|
||||||
}
|
}
|
||||||
var resultErr error
|
var resultErr error
|
||||||
for _, rule := range cfg.PublicationOutputs() {
|
for _, rule := range rules {
|
||||||
destination, _, err := helperPublishedOutputDest(rule, catalog)
|
destination, err := artifactpolicy.ResolvePublishedDestinationWithExtractions(strings.TrimSpace(rule.Source), rule.Dest, configuredOutputs, extractionOutputs)
|
||||||
_, isLocked := locked[rule.Source]
|
_, isLocked := locked[rule.Source]
|
||||||
output := sessionPublishedOutput{Source: rule.Source, Destination: destination, Required: rule.Required == nil || *rule.Required, LockState: "unknown", State: "missing", Outcome: outcomes[rule.Source]}
|
output := sessionPublishedOutput{Source: rule.Source, Destination: destination, Required: rule.Required == nil || *rule.Required, LockState: "unknown", State: "missing", Outcome: outcomes[rule.Source]}
|
||||||
if locksKnown {
|
if locksKnown {
|
||||||
@@ -267,7 +274,7 @@ func inspectPublishedOutputs(ctx context.Context, cfg *config.Config, store stor
|
|||||||
output.State = "error"
|
output.State = "error"
|
||||||
}
|
}
|
||||||
if err == nil && current != nil && current.Commit != nil {
|
if err == nil && current != nil && current.Commit != nil {
|
||||||
if declaration, ok := committedPublishedOutput(current.Commit, rule.Source); ok {
|
if declaration, ok := declarations[rule.Source]; ok {
|
||||||
identity, identityErr := artifacts.ParsePublishedOutputObjectKey(current.SessionPrefix, declaration.DestinationKey)
|
identity, identityErr := artifacts.ParsePublishedOutputObjectKey(current.SessionPrefix, declaration.DestinationKey)
|
||||||
if identityErr != nil {
|
if identityErr != nil {
|
||||||
err = identityErr
|
err = identityErr
|
||||||
|
|||||||
Reference in New Issue
Block a user