Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
24e746cd
Unverified
Commit
24e746cd
authored
5 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Use delay for cache-backend-instance so there is no thrashing on init
parent
aad627e0
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/query_processor/middleware/cache.clj
+15
-14
15 additions, 14 deletions
src/metabase/query_processor/middleware/cache.clj
with
15 additions
and
14 deletions
src/metabase/query_processor/middleware/cache.clj
+
15
−
14
View file @
24e746cd
...
...
@@ -18,9 +18,12 @@
[
config
:as
config
]
[
public-settings
:as
public-settings
]
[
util
:as
u
]]
[
metabase.plugins.classloader
:as
classloader
]
[
metabase.query-processor.middleware.cache-backend.interface
:as
i
]
[
metabase.query-processor.util
:as
qputil
]
[
metabase.util.date
:as
du
]))
[
metabase.util
[
date
:as
du
]
[
i18n
:refer
[
trs
]]]))
;; TODO - Why not make this an option in the query itself? :confused:
(
def
^
:dynamic
^
Boolean
*ignore-cached-results*
...
...
@@ -31,13 +34,10 @@
;;; ---------------------------------------------------- Backend -----------------------------------------------------
(
def
^
:private
backend-instance
(
atom
nil
))
(
defn-
valid-backend?
[
instance
]
(
extends?
i/IQueryProcessorCacheBackend
(
class
instance
)))
(
defn-
get-backend-instance-in-namespace
"Return a valid query cache backend
`
instance
`
in
BACKEND-NS-SYMB
, or throw an Exception if none exists."
"Return a valid query cache backend instance in
`backend-ns-symb`
, or throw an Exception if none exists."
;; if for some reason the resolved var doesn't satisfy `IQueryProcessorCacheBackend` we'll reload the namespace
;; it belongs to and try one more time.
;; This fixes the issue in dev sessions where the interface namespace gets reloaded causing the cache implementation
...
...
@@ -54,19 +54,23 @@
:else
(
throw
(
Exception.
(
format
"%s/instance doesn't satisfy IQueryProcessorCacheBackend"
backend-ns-symb
)))))))
(
defn-
set
-backend
!
"
S
et the cache backend to the cache defined by the keyword
BACKEND
.
(
defn-
resolve
-backend
"
G
et the cache backend to the cache defined by the keyword
`backend`
.
(This should be something like `:db`, `:redis`, or `:memcached`. See the
documentation in `metabase.query-processor.middleware.cache-backend.interface` for details on how this works.)"
([]
(
set-backend!
(
config/config-kw
:mb-qp-cache-backend
)))
(
resolve-backend
(
config/config-kw
:mb-qp-cache-backend
)))
([
backend
]
(
classloader/the-classloader
)
(
let
[
backend-ns-symb
(
symbol
(
str
"metabase.query-processor.middleware.cache-backend."
(
munge
(
name
backend
))))]
(
require
backend-ns-symb
)
(
log/info
"Using query processor cache backend:"
(
u/format-color
'blue
backend
)
(
u/emoji
"💾"
))
(
reset!
backend-instance
(
get-backend-instance-in-namespace
backend-ns-symb
))))
)
(
log/info
(
trs
"Using query processor cache backend:
{0}
"
(
u/format-color
'blue
backend
)
)
(
u/emoji
"💾"
))
(
get-backend-instance-in-namespace
backend-ns-symb
))))
(
defonce
^
:private
backend-instance
(
delay
(
resolve-backend
)))
;;; ------------------------------------------------ Cache Operations ------------------------------------------------
...
...
@@ -130,7 +134,4 @@
;; wait until we're actually going to use the cache before initializing the backend. We don't want to initialize
;; it when the files get compiled, because that would give it the wrong version of the
;; `IQueryProcessorCacheBackend` protocol
(
do
(
when-not
@
backend-instance
(
set-backend!
))
(
run-query-with-cache
qp
query
respond
raise
canceled-chan
)))))
(
run-query-with-cache
qp
query
respond
raise
canceled-chan
))))
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