mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
perf(core): build the signed service route prefixes once (#7802)
Five route filters test the path of every request of every service. Each test built the root path plus a slash, and each filter built its internal prefix test again on every request. That was about 350 bytes per request.
This commit is contained in:
1 parent
ab312d68e6
commit
d9a258ae44
1 file changed
+6
-2
@@ -29,6 +29,7 @@ public final class SignedServiceRoute {
|
||||
private final ResolvedServiceCatalog catalog;
|
||||
private final Set<String> externalKeys;
|
||||
private final String internalPrefix;
|
||||
private final Predicate<String> internalPaths;
|
||||
private final Predicate<String> publicPaths;
|
||||
|
||||
/**
|
||||
@@ -58,12 +59,15 @@ public final class SignedServiceRoute {
|
||||
this.catalog = catalog;
|
||||
this.externalKeys = Set.copyOf(externalKeys);
|
||||
this.internalPrefix = internalPrefix;
|
||||
this.internalPaths = under(internalPrefix);
|
||||
this.publicPaths = publicPaths;
|
||||
}
|
||||
|
||||
/** Matches {@code root} itself and every path beneath it. */
|
||||
public static Predicate<String> under(String root) {
|
||||
return path -> path.equals(root) || path.startsWith(root + "/");
|
||||
// Every request of every service runs these tests, so the prefix is built once.
|
||||
String beneath = root + "/";
|
||||
return path -> path.equals(root) || path.startsWith(beneath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,7 +84,7 @@ public final class SignedServiceRoute {
|
||||
String path = ctx.getUriInfo().getPath();
|
||||
String normalizedPath = path.startsWith("/") ? path : "/" + path;
|
||||
|
||||
if (under(internalPrefix).test(normalizedPath)) {
|
||||
if (internalPaths.test(normalizedPath)) {
|
||||
if (!signedForService(ctx)) {
|
||||
ctx.abortWith(invalidBucketName());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user