Skip to content

Commit

Permalink
put href prop before _shortest_ similarly named key (#265)
Browse files Browse the repository at this point in the history
PDOK-17329
  • Loading branch information
roelarents authored Dec 12, 2024
1 parent 3512b73 commit 4b1b6cb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/ogc/features/domain/props.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (p *FeatureProperties) SetRelation(key string, value any, existingKeyPrefix
p.moveKeyBeforePrefix(key, existingKeyPrefix)
}

// moveKeyBeforePrefix best-effort algorithm to place the feature relation BEFORE any similarly named keys.
// moveKeyBeforePrefix best-effort algorithm to place the feature relation BEFORE the first shortest of any similarly named keys.
// For example, places "building.href" before "building_fk" or "building_fid".
func (p *FeatureProperties) moveKeyBeforePrefix(key string, keyPrefix string) {
if p.unordered != nil {
Expand All @@ -78,8 +78,10 @@ func (p *FeatureProperties) moveKeyBeforePrefix(key string, keyPrefix string) {
var existingKey string
for pair := p.ordered.Oldest(); pair != nil; pair = pair.Next() {
if strings.HasPrefix(pair.Key, keyPrefix) {
if existingKey != "" && len(existingKey) <= len(pair.Key) {
continue
}
existingKey = pair.Key
break
}
}
if existingKey != "" {
Expand Down

0 comments on commit 4b1b6cb

Please sign in to comment.