Skip to content

Commit

Permalink
low-fi caching for globs matching engine, too.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebullient committed Feb 5, 2024
1 parent a323477 commit 395db39
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public QueryContext newQueryContext(EventData eventData, GitHub github) {
return newQueryContext(eventData).addExisting(github);
}

static <T> T getCache(String itemId, String key, Class<T> type) {
public static <T> T getCache(String itemId, String key, Class<T> type) {
String idx = itemId + ":" + key;
T result = (T) cache.getIfPresent(idx);
if (result != null) {
Expand All @@ -59,7 +59,7 @@ static <T> T getCache(String itemId, String key, Class<T> type) {
return result;
}

static void putCache(String itemId, String key, Object value) {
public static void putCache(String itemId, String key, Object value) {
String idx = itemId + ":" + key;
System.out.println(":: UPDATE :: " + idx + " ::: ");
cache.put(idx, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import org.commonhaus.automation.github.EventData;
import org.commonhaus.automation.github.QueryHelper;
import org.commonhaus.automation.github.QueryHelper.QueryContext;
import org.commonhaus.automation.github.model.EventType;
import org.kohsuke.github.GHEventPayload;
Expand Down Expand Up @@ -55,8 +56,12 @@ public boolean matches(QueryContext queryContext) {
return false;
}

//@CacheResult(cacheName = "glob-cache")
MatchingEngine compileGlob(String filenamePattern) {
return GlobPattern.compile(filenamePattern);
MatchingEngine me = QueryHelper.getCache("GLOB", filenamePattern, MatchingEngine.class);
if (me == null) {
me = GlobPattern.compile(filenamePattern);
QueryHelper.putCache("GLOB", filenamePattern, me);
}
return me;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.kohsuke.github.PagedIterator;
import org.mockito.Mockito;

import com.hrakaroo.glob.MatchingEngine;

import io.quarkiverse.githubapp.testing.GitHubAppTest;
import io.quarkus.test.junit.QuarkusTest;
import io.smallrye.graphql.client.Response;
Expand Down Expand Up @@ -246,6 +248,10 @@ void testRelevantPr() throws Exception {
});

verifyLabelCache(prNodeId, 1, List.of("notice"));
Assertions.assertNotNull(QueryHelper.getCache("GLOB", "bylaws/*", Object.class),
"bylaws/* GLOB cache should exist");
Assertions.assertNull(QueryHelper.getCache("GLOB", "policy/*", Object.class),
"policy/* GLOB cache should not exist");
}

private void verifyLabelCache(String discussionId, int size, List<String> expectedLabels) {
Expand Down

0 comments on commit 395db39

Please sign in to comment.