-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ocs cache warmup strategy for first request from the user
- Loading branch information
Showing
8 changed files
with
152 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Enhancement: Add ocs cache warmup strategy for first request from the user | ||
|
||
https://github.com/cs3org/reva/pull/2117 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2018-2021 CERN | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// In applying this license, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
package ocs | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
|
||
ctxpkg "github.com/cs3org/reva/pkg/ctx" | ||
"google.golang.org/grpc/metadata" | ||
) | ||
|
||
func (s *svc) cacheWarmup(w http.ResponseWriter, r *http.Request) { | ||
if s.warmupCache != nil { | ||
u := ctxpkg.ContextMustGetUser(r.Context()) | ||
tkn := ctxpkg.ContextMustGetToken(r.Context()) | ||
|
||
ctx := context.Background() | ||
ctx = ctxpkg.ContextSetUser(ctx, u) | ||
ctx = ctxpkg.ContextSetToken(ctx, tkn) | ||
ctx = metadata.AppendToOutgoingContext(ctx, ctxpkg.TokenHeader, tkn) | ||
req := r.Clone(ctx) | ||
req.Method = http.MethodGet | ||
|
||
id := u.Id.OpaqueId | ||
if _, err := s.warmupCache.Get(id); err != nil { | ||
p := httptest.NewRecorder() | ||
_ = s.warmupCache.Set(id, true) | ||
req.URL.Path = "/apps/files_sharing/api/v1/shares" | ||
go s.router.ServeHTTP(p, req) | ||
req.URL.Path = "/apps/files_sharing/api/v1/shares?shared_with_me=true" | ||
go s.router.ServeHTTP(p, req) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2018-2021 CERN | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// In applying this license, CERN does not waive the privileges and immunities | ||
// granted to it by virtue of its status as an Intergovernmental Organization | ||
// or submit itself to any jurisdiction. | ||
|
||
package loader | ||
|
||
import ( | ||
// Load share cache drivers. | ||
_ "github.com/cs3org/reva/pkg/share/cache/cbox" | ||
// Add your own here | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters