feat(topdata): anchor autogen lock identity on model path with cutover remap
Lock identity for accessory VFX rows is now the model source path (dataset:group/subgroup/file.mdl) rather than the config-derived presentation key. Config-only edits (key_format, delimiter, case, strip_prefixes) no longer reshuffle row IDs. Adds: accessoryVisualeffectLockKey, hasKey helper, stale pruning loop (managed keys with no live entry are freed), and one-time cutover remap (old config-derived key in historical lock → new model-path key, with the old key pruned). autogenConsumerManagedLockKeyMatcher is now config-independent (dataset prefix + first path segment ∈ policy groups). Updates autogen_manifest_file_test.go and topdata_test.go lock-key assertions to match the new model-path scheme.
This commit is contained in:
+61
-15
@@ -182,17 +182,18 @@ func preserveAutogenConsumerLockEntries(collected []nativeCollectedDataset, cons
|
||||
func autogenConsumerManagedLockKeyMatcher(consumer project.AutogenConsumerConfig) func(string) bool {
|
||||
switch consumer.Mode {
|
||||
case "accessory_visualeffects":
|
||||
policy := resolveAccessoryVisualeffectsPolicy(consumer, nil)
|
||||
delimiter := policy.Delimiter
|
||||
if delimiter == "" {
|
||||
delimiter = "/"
|
||||
dataset := strings.TrimSpace(consumer.Dataset)
|
||||
if dataset == "" {
|
||||
dataset = "visualeffects"
|
||||
}
|
||||
prefix := "visualeffects:"
|
||||
prefix := dataset + ":"
|
||||
// Build the group set from the resolved policy so consumers that omit
|
||||
// AccessoryVisualeffects.Groups still match the four default group names.
|
||||
policy := resolveAccessoryVisualeffectsPolicy(consumer, nil)
|
||||
groups := make(map[string]struct{}, len(policy.Groups))
|
||||
for group, groupPolicy := range policy.Groups {
|
||||
token := applyAccessoryVisualeffectCase(accessoryVisualeffectGroupToken(group, groupPolicy, policy), policy)
|
||||
if strings.TrimSpace(token) != "" {
|
||||
groups[token] = struct{}{}
|
||||
for group := range policy.Groups {
|
||||
if group = strings.TrimSpace(group); group != "" {
|
||||
groups[group] = struct{}{}
|
||||
}
|
||||
}
|
||||
if len(groups) == 0 {
|
||||
@@ -203,7 +204,7 @@ func autogenConsumerManagedLockKeyMatcher(consumer project.AutogenConsumerConfig
|
||||
return false
|
||||
}
|
||||
rest := key[len(prefix):]
|
||||
idx := strings.Index(rest, delimiter)
|
||||
idx := strings.Index(rest, "/")
|
||||
if idx <= 0 {
|
||||
return false
|
||||
}
|
||||
@@ -1054,30 +1055,61 @@ func augmentWithAutogeneratedAccessoryVisualeffects(collected []nativeCollectedD
|
||||
return rowID
|
||||
}
|
||||
|
||||
liveLockKeys := make(map[string]struct{}, len(entries))
|
||||
for _, entry := range entries {
|
||||
key, label, modelStem, groupPolicy, ok := accessoryVisualeffectIdentity(dataset.Dataset.Name, entry, policy)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
lockKey := accessoryVisualeffectLockKey(dataset.Dataset.Name, entry)
|
||||
liveLockKeys[lockKey] = struct{}{}
|
||||
|
||||
if existing, exists := rowByKey[key]; exists {
|
||||
applyDiscoveredAccessoryVisualeffectDefaults(existing, dataset.Columns, modelStem, label, policy, groupPolicy)
|
||||
if _, pinned := lockData[lockKey]; !pinned {
|
||||
if rowID, ok := existing["id"].(int); ok {
|
||||
lockData[lockKey] = rowID
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
rowID, ok := lockData[key]
|
||||
rowID, ok := lockData[lockKey]
|
||||
if !ok {
|
||||
if preservedRowID, preserved := historicalLockData[key]; preserved {
|
||||
rowID = preservedRowID
|
||||
} else {
|
||||
switch {
|
||||
case hasKey(historicalLockData, lockKey):
|
||||
rowID = historicalLockData[lockKey]
|
||||
case hasKey(historicalLockData, key):
|
||||
// One-time cutover: adopt the ID from the old config-derived key
|
||||
// so IDs carry over with zero shift on the key-scheme switch. The
|
||||
// stale old key is pruned below.
|
||||
rowID = historicalLockData[key]
|
||||
default:
|
||||
rowID = allocateNextID()
|
||||
}
|
||||
lockData[key] = rowID
|
||||
lockData[lockKey] = rowID
|
||||
}
|
||||
newRow := createDefaultAccessoryVisualeffectRow(dataset.Columns, rowID, key, label, modelStem, policy, groupPolicy)
|
||||
rows = append(rows, newRow)
|
||||
rowByKey[key] = newRow
|
||||
}
|
||||
|
||||
// Stale pruning: drop managed lock keys (this consumer's accessory keys,
|
||||
// incl. now-superseded old config-scheme keys) that no live entry resolves
|
||||
// to, freeing their IDs for first-free reuse. Safe here because the
|
||||
// augmentor only runs on a successful, non-empty resolution; the fail-open
|
||||
// paths skip it entirely and never reach this code.
|
||||
if managed := autogenConsumerManagedLockKeyMatcher(consumer); managed != nil {
|
||||
for lk := range lockData {
|
||||
if _, live := liveLockKeys[lk]; live {
|
||||
continue
|
||||
}
|
||||
if managed(lk) {
|
||||
delete(lockData, lk)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slices.SortFunc(rows, func(a, b map[string]any) int {
|
||||
return a["id"].(int) - b["id"].(int)
|
||||
})
|
||||
@@ -1096,6 +1128,20 @@ func nextAvailableAutogenID(used map[int]struct{}) int {
|
||||
}
|
||||
}
|
||||
|
||||
// accessoryVisualeffectLockKey is the model-anchored autogen lock identity:
|
||||
// the dataset namespace prefix plus the model source path from vfxs.yml (leading
|
||||
// vfxs/ already stripped on entry.Source). Config-derived presentation parts
|
||||
// (group token, category, delimiter, case, prefix-stripping) are deliberately
|
||||
// excluded so a config-only edit never reshuffles row IDs.
|
||||
func accessoryVisualeffectLockKey(dataset string, entry autogenManifestEntry) string {
|
||||
return dataset + ":" + strings.TrimPrefix(filepath.ToSlash(strings.TrimSpace(entry.Source)), "vfxs/")
|
||||
}
|
||||
|
||||
func hasKey(m map[string]int, key string) bool {
|
||||
_, ok := m[key]
|
||||
return ok
|
||||
}
|
||||
|
||||
type accessoryVisualeffectsPolicy struct {
|
||||
Groups map[string]accessoryVisualeffectsGroupPolicy
|
||||
GroupTokenSource string
|
||||
|
||||
Reference in New Issue
Block a user