Skip to content

Commit

Permalink
Cache components #80
Browse files Browse the repository at this point in the history
  • Loading branch information
rymsha committed Dec 18, 2024
1 parent c9f6ac8 commit 20c9a72
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/com/enonic/app/booster/Preconditions.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ public Result check( final HttpServletRequest request )
return Result.SILENT_BYPASS;
}

// If path contains /_/ it is a controller request. We don't cache them here at least for now.
// If path contains /_/ it is a controller request.
// We cache /_/component/ controller requests, but not the other ones.
final String requestURI = request.getRequestURI();
if ( requestURI.contains( "/_/" ) )
final int indexOfUnderscore = requestURI.indexOf( "/_/" );
if ( indexOfUnderscore != -1 &&
!requestURI.regionMatches( indexOfUnderscore + "/_/".length(), "component/", 0, "component/".length() ) )
{
LOG.debug( "Bypassing request with uri {}", requestURI );
return Result.SILENT_BYPASS;
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/enonic/app/booster/PreconditionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,28 @@ void preconditions_service()
assertTrue( preconditions.check( request ).bypass() );
}

@Test
void preconditions_component_service_incomplete()
{
when( request.getScheme() ).thenReturn( "https" );
when( request.getMethod() ).thenReturn( "GET" );
when( request.getRequestURI() ).thenReturn( "/site/repo/master/_/component" );

Preconditions preconditions = new Preconditions();
assertTrue( preconditions.check( request ).bypass() );
}

@Test
void preconditions_component_service()
{
when( request.getScheme() ).thenReturn( "https" );
when( request.getMethod() ).thenReturn( "GET" );
when( request.getRequestURI() ).thenReturn( "/site/repo/master/_/component/main/0" );

Preconditions preconditions = new Preconditions();
assertFalse( preconditions.check( request ).bypass() );
}

@Test
void no_license()
{
Expand Down

0 comments on commit 20c9a72

Please sign in to comment.