Skip to content

Commit 82220b4

Browse files
authored
Cache by Strings rather than ZoneId and Locale (#95299)
1 parent 778f099 commit 82220b4

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/DateProcessor.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,24 @@ public final class DateProcessor extends AbstractProcessor {
8181
for (String format : formats) {
8282
DateFormat dateFormat = DateFormat.fromString(format);
8383
dateParsers.add((params) -> {
84-
var documentZoneId = newDateTimeZone(params);
85-
var documentLocale = newLocale(params);
84+
var documentTimezone = timezone == null ? null : timezone.newInstance(params).execute();
85+
var documentLocale = locale == null ? null : locale.newInstance(params).execute();
8686
return Cache.INSTANCE.getOrCompute(
87-
new Cache.Key(format, documentZoneId, documentLocale),
88-
() -> dateFormat.getFunction(format, documentZoneId, documentLocale)
87+
new Cache.Key(format, documentTimezone, documentLocale),
88+
() -> dateFormat.getFunction(format, newDateTimeZone(documentTimezone), newLocale(documentLocale))
8989
);
9090
});
9191
}
9292
this.outputFormat = outputFormat;
9393
formatter = DateFormatter.forPattern(this.outputFormat);
9494
}
9595

96-
private ZoneId newDateTimeZone(Map<String, Object> params) {
97-
return timezone == null ? ZoneOffset.UTC : ZoneId.of(timezone.newInstance(params).execute());
96+
private static ZoneId newDateTimeZone(String timezone) {
97+
return timezone == null ? ZoneOffset.UTC : ZoneId.of(timezone);
9898
}
9999

100-
private Locale newLocale(Map<String, Object> params) {
101-
return locale == null ? Locale.ROOT : LocaleUtils.parse(locale.newInstance(params).execute());
100+
private static Locale newLocale(String locale) {
101+
return locale == null ? Locale.ROOT : LocaleUtils.parse(locale);
102102
}
103103

104104
@Override
@@ -255,6 +255,6 @@ Function<String, ZonedDateTime> getOrCompute(Key key, Supplier<Function<String,
255255
return fn;
256256
}
257257

258-
record Key(String format, ZoneId zoneId, Locale locale) {}
258+
record Key(String format, String zoneId, String locale) {}
259259
}
260260
}

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/DateProcessorTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ public void testCacheIsEvictedAfterReachMaxCapacity() {
349349
Function<String, ZonedDateTime> zonedDateTimeFunction1 = str -> ZonedDateTime.now();
350350
Function<String, ZonedDateTime> zonedDateTimeFunction2 = str -> ZonedDateTime.now();
351351
var cache = new DateProcessor.Cache(1);
352-
var key1 = new DateProcessor.Cache.Key("format-1", ZoneId.systemDefault(), Locale.ROOT);
353-
var key2 = new DateProcessor.Cache.Key("format-2", ZoneId.systemDefault(), Locale.ROOT);
352+
var key1 = new DateProcessor.Cache.Key("format-1", ZoneId.systemDefault().toString(), Locale.ROOT.toString());
353+
var key2 = new DateProcessor.Cache.Key("format-2", ZoneId.systemDefault().toString(), Locale.ROOT.toString());
354354

355355
when(supplier1.get()).thenReturn(zonedDateTimeFunction1);
356356
when(supplier2.get()).thenReturn(zonedDateTimeFunction2);

0 commit comments

Comments
 (0)