Skip to content

Commit

Permalink
Cache profile prefixes (#1217)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Aug 29, 2024
1 parent 30f478c commit 3439e70
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
@Priority(Priorities.LIBRARY + 200)
public class ProfileConfigSourceInterceptor implements ConfigSourceInterceptor {
private static final long serialVersionUID = -6305289277993917313L;

private final List<String> profiles;
private final List<String> prefixProfiles;

public ProfileConfigSourceInterceptor(final String profile) {
this(profile != null ? convertProfile(profile) : new ArrayList<>());
Expand All @@ -27,13 +29,17 @@ public ProfileConfigSourceInterceptor(final List<String> profiles) {
List<String> reverseProfiles = new ArrayList<>(profiles);
Collections.reverse(reverseProfiles);
this.profiles = reverseProfiles;
this.prefixProfiles = new ArrayList<>();
for (String profile : this.profiles) {
this.prefixProfiles.add("%" + profile + ".");
}
}

@Override
public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) {
if (profiles.size() > 0) {
final String normalizeName = activeName(name, profiles);
final ConfigValue profileValue = getProfileValue(context, normalizeName);
if (!profiles.isEmpty()) {
String normalizeName = activeName(name, profiles);
ConfigValue profileValue = getProfileValue(context, normalizeName);
if (profileValue != null) {
final ConfigValue originalValue = context.proceed(normalizeName);
if (originalValue != null && CONFIG_SOURCE_COMPARATOR.compare(originalValue, profileValue) > 0) {
Expand All @@ -47,8 +53,9 @@ public ConfigValue getValue(final ConfigSourceInterceptorContext context, final
}

public ConfigValue getProfileValue(final ConfigSourceInterceptorContext context, final String normalizeName) {
for (String profile : profiles) {
final ConfigValue profileValue = context.proceed("%" + profile + "." + normalizeName);
for (int i = 0; i < profiles.size(); i++) {
String profile = profiles.get(i);
ConfigValue profileValue = context.proceed(prefixProfiles.get(i).concat(normalizeName));
if (profileValue != null) {
return profileValue.withProfile(profile);
}
Expand Down

0 comments on commit 3439e70

Please sign in to comment.