|
47 | 47 | _ resource.Cloner = (*genericResource)(nil) |
48 | 48 | _ resource.ResourcesLanguageMerger = (*resource.Resources)(nil) |
49 | 49 | _ resource.Identifier = (*genericResource)(nil) |
| 50 | + _ resource.TransientIdentifier = (*genericResource)(nil) |
50 | 51 | _ targetPathProvider = (*genericResource)(nil) |
51 | 52 | _ sourcePathProvider = (*genericResource)(nil) |
52 | 53 | _ identity.IdentityGroupProvider = (*genericResource)(nil) |
@@ -359,6 +360,9 @@ func GetTestInfoForResource(r resource.Resource) GenericResourceTestInfo { |
359 | 360 | type genericResource struct { |
360 | 361 | publishInit *sync.Once |
361 | 362 |
|
| 363 | + key string |
| 364 | + keyInit *sync.Once |
| 365 | + |
362 | 366 | sd ResourceSourceDescriptor |
363 | 367 | paths internal.ResourcePaths |
364 | 368 |
|
@@ -444,19 +448,24 @@ func (l *genericResource) Data() any { |
444 | 448 | } |
445 | 449 |
|
446 | 450 | func (l *genericResource) Key() string { |
447 | | - basePath := l.spec.Cfg.BaseURL().BasePathNoTrailingSlash |
448 | | - var key string |
449 | | - if basePath == "" { |
450 | | - key = l.RelPermalink() |
451 | | - } else { |
452 | | - key = strings.TrimPrefix(l.RelPermalink(), basePath) |
453 | | - } |
| 451 | + l.keyInit.Do(func() { |
| 452 | + basePath := l.spec.Cfg.BaseURL().BasePathNoTrailingSlash |
| 453 | + if basePath == "" { |
| 454 | + l.key = l.RelPermalink() |
| 455 | + } else { |
| 456 | + l.key = strings.TrimPrefix(l.RelPermalink(), basePath) |
| 457 | + } |
454 | 458 |
|
455 | | - if l.spec.Cfg.IsMultihost() { |
456 | | - key = l.spec.Lang() + key |
457 | | - } |
| 459 | + if l.spec.Cfg.IsMultihost() { |
| 460 | + l.key = l.spec.Lang() + l.key |
| 461 | + } |
| 462 | + }) |
| 463 | + |
| 464 | + return l.key |
| 465 | +} |
458 | 466 |
|
459 | | - return key |
| 467 | +func (l *genericResource) TransientKey() string { |
| 468 | + return l.Key() |
460 | 469 | } |
461 | 470 |
|
462 | 471 | func (l *genericResource) targetPath() string { |
@@ -623,6 +632,7 @@ func (rc *genericResource) cloneWithUpdates(u *transformationUpdate) (baseResour |
623 | 632 |
|
624 | 633 | func (l genericResource) clone() *genericResource { |
625 | 634 | l.publishInit = &sync.Once{} |
| 635 | + l.keyInit = &sync.Once{} |
626 | 636 | return &l |
627 | 637 | } |
628 | 638 |
|
|
0 commit comments