Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cf-online-api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KS Pardubický kraj
cf-online-api
Commits
279764e7
Verified
Commit
279764e7
authored
4 years ago
by
Andrej Ramašeuski
Browse files
Options
Downloads
Patches
Plain Diff
Pridan redis cache
parent
51f25247
No related branches found
No related tags found
No related merge requests found
Pipeline
#2956
passed
4 years ago
Stage: build
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitlab-ci.yml
+1
-1
1 addition, 1 deletion
.gitlab-ci.yml
Dockerfile
+1
-0
1 addition, 0 deletions
Dockerfile
lib/CF.pm
+5
-0
5 additions, 0 deletions
lib/CF.pm
lib/CF/Controller/SSO.pm
+13
-2
13 additions, 2 deletions
lib/CF/Controller/SSO.pm
with
20 additions
and
3 deletions
.gitlab-ci.yml
+
1
−
1
View file @
279764e7
...
@@ -2,7 +2,7 @@ image: docker:19.03.12
...
@@ -2,7 +2,7 @@ image: docker:19.03.12
variables
:
variables
:
DOCKER_TLS_CERTDIR
:
"
/certs"
DOCKER_TLS_CERTDIR
:
"
/certs"
IMAGE_VER
:
1.1
0.2
IMAGE_VER
:
1.1
1.0
services
:
services
:
-
docker:19.03.12-dind
-
docker:19.03.12-dind
...
...
This diff is collapsed.
Click to expand it.
Dockerfile
+
1
−
0
View file @
279764e7
...
@@ -18,6 +18,7 @@ RUN apt-get update && apt-get install -y \
...
@@ -18,6 +18,7 @@ RUN apt-get update && apt-get install -y \
RUN
cpanm
\
RUN
cpanm
\
Mojolicious
\
Mojolicious
\
Mojo::Pg
\
Mojo::Pg
\
Mojo::Redis
\
Mojo::JWT
\
Mojo::JWT
\
Mojolicious::Plugin::OpenAPI
Mojolicious::Plugin::OpenAPI
...
...
This diff is collapsed.
Click to expand it.
lib/CF.pm
+
5
−
0
View file @
279764e7
...
@@ -2,6 +2,7 @@ package CF;
...
@@ -2,6 +2,7 @@ package CF;
use
Mojo::
Base
'
Mojolicious
';
use
Mojo::
Base
'
Mojolicious
';
use
Mojo::
Pg
;
use
Mojo::
Pg
;
use
Mojo::
JWT
;
use
Mojo::
JWT
;
use
Mojo::
Redis
;
use
CF::
Schema
;
use
CF::
Schema
;
# This method will run once at server start
# This method will run once at server start
...
@@ -37,6 +38,10 @@ sub startup {
...
@@ -37,6 +38,10 @@ sub startup {
});
});
$self
->
helper
(
schema
=>
sub
{
return
$schema
;
}
);
$self
->
helper
(
schema
=>
sub
{
return
$schema
;
}
);
# Redis
my
$redis
=
Mojo::
Redis
->
new
(
$cfg
->
{
redis
}
);
$self
->
helper
(
redis
=>
sub
{
return
$redis
;
}
);
$self
->
plugin
('
CF::Helpers::Core
');
$self
->
plugin
('
CF::Helpers::Core
');
$self
->
plugin
('
CF::Helpers::Auth
');
$self
->
plugin
('
CF::Helpers::Auth
');
...
...
This diff is collapsed.
Click to expand it.
lib/CF/Controller/SSO.pm
+
13
−
2
View file @
279764e7
package
CF::Controller::
SSO
;
package
CF::Controller::
SSO
;
use
Mojo::
Base
'
Mojolicious::Controller
';
use
Mojo::Pg::
PubSub
;
use
feature
'
signatures
';
use
feature
'
signatures
';
no
warnings
qw{ experimental::signatures }
;
no
warnings
qw{ experimental::signatures }
;
use
Mojo::
Base
'
Mojolicious::Controller
';
use
Mojo::Pg::
PubSub
;
use
Mojo::
UserAgent
;
use
Mojo::
UserAgent
;
use
JSON
;
use
constant
REDIS_CACHE_LIFETIME
=>
300
;
use
constant
REDIS_CACHE_KEY
=>
'
SSO SUBJECTS %s
';
sub
subjects
($c) {
sub
subjects
($c) {
$c
->
openapi
->
valid_input
or
return
;
$c
->
openapi
->
valid_input
or
return
;
my
$args
=
$c
->
validation
->
output
;
my
$args
=
$c
->
validation
->
output
;
my
$cache_key
=
sprintf
(
REDIS_CACHE_KEY
,
$args
->
{
search
});
if
(
$c
->
redis
->
db
->
exists
(
$cache_key
))
{
$c
->
render
(
openapi
=>
from_json
(
$c
->
redis
->
db
->
get
(
$cache_key
)));
return
;
}
my
(
$groups
,
$users
,
@subjects
);
my
(
$groups
,
$users
,
@subjects
);
if
(
$args
->
{
class
}
=~
/all|group/
)
{
if
(
$args
->
{
class
}
=~
/all|group/
)
{
...
@@ -20,6 +30,7 @@ sub subjects ($c) {
...
@@ -20,6 +30,7 @@ sub subjects ($c) {
@subjects
=
(
@subjects
,
$c
->
_users
(
$args
->
{
search
}
));
@subjects
=
(
@subjects
,
$c
->
_users
(
$args
->
{
search
}
));
}
}
$c
->
redis
->
db
->
set
(
$cache_key
,
to_json
(
\
@subjects
),
'
EX
',
REDIS_CACHE_LIFETIME
);
$c
->
render
(
openapi
=>
\
@subjects
);
$c
->
render
(
openapi
=>
\
@subjects
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment