Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-django-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-django-backend
Commits
72dc640a
Verified
Commit
72dc640a
authored
Feb 25, 2021
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
WIP: local caching
parent
29747a3b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
djaosdb/caosdb_client.py
+18
-10
18 additions, 10 deletions
djaosdb/caosdb_client.py
with
18 additions
and
10 deletions
djaosdb/caosdb_client.py
+
18
−
10
View file @
72dc640a
...
@@ -112,6 +112,9 @@ class CachedProperties(set):
...
@@ -112,6 +112,9 @@ class CachedProperties(set):
class
DefaultCaosDBClientDelegate
:
class
DefaultCaosDBClientDelegate
:
_query_cache
=
{}
_etag
=
None
def
__init__
(
self
,
**
kwargs
):
def
__init__
(
self
,
**
kwargs
):
self
.
cached_record_types
=
CachedRecordTypes
(
self
)
self
.
cached_record_types
=
CachedRecordTypes
(
self
)
self
.
cached_properties
=
CachedProperties
(
self
)
self
.
cached_properties
=
CachedProperties
(
self
)
...
@@ -121,8 +124,7 @@ class DefaultCaosDBClientDelegate:
...
@@ -121,8 +124,7 @@ class DefaultCaosDBClientDelegate:
self
.
_caosdb
=
caosdb
self
.
_caosdb
=
caosdb
self
.
_caosdb
.
configure_connection
(
**
kwargs
)
self
.
_caosdb
.
configure_connection
(
**
kwargs
)
self
.
_query_cache
=
{}
self
.
_etag
=
None
def
_get_reference_clause
(
self
,
type
,
p
,
v
,
negation
,
sub
=
None
):
def
_get_reference_clause
(
self
,
type
,
p
,
v
,
negation
,
sub
=
None
):
result
=
(
f
"
REFERENCES
{
v
}
"
result
=
(
f
"
REFERENCES
{
v
}
"
...
@@ -165,26 +167,32 @@ class DefaultCaosDBClientDelegate:
...
@@ -165,26 +167,32 @@ class DefaultCaosDBClientDelegate:
raise
NotImplementedError
(
"
_get_filter_clause(%s)
"
,
fil
)
raise
NotImplementedError
(
"
_get_filter_clause(%s)
"
,
fil
)
def
_cache_locally
(
self
,
etag
,
key
,
value
):
def
_cache_locally
(
self
,
etag
,
key
,
value
):
if
etag
!=
self
.
_etag
:
if
etag
!=
DefaultCaosDBClientDelegate
.
_etag
:
self
.
_query_cache
=
{}
DefaultCaosDBClientDelegate
.
_query_cache
=
{}
DefaultCaosDBClientDelegate
.
_etag
=
etag
if
key
is
not
None
:
if
key
is
not
None
:
self
.
_query_cache
[
key
]
=
value
LOGGER
.
debug
(
"
caching results with etag
'
%s
'
for key
'
%s
'"
,
str
(
etag
),
str
(
key
))
DefaultCaosDBClientDelegate
.
_query_cache
[
key
]
=
value
def
_query
(
self
,
query
,
key
=
None
):
def
_query
(
self
,
query
,
key
=
None
):
if
key
is
not
None
and
key
in
self
.
query_local_cache
:
if
key
is
not
None
and
key
in
DefaultCaosDBClientDelegate
.
_query_cache
:
return
self
.
_query_cache
[
key
]
LOGGER
.
debug
(
"
using cached results for key
'
%s
'"
,
str
(
key
))
return
DefaultCaosDBClientDelegate
.
_query_cache
[
key
]
result
=
self
.
_query_no_local_cache
(
query
)
result
,
etag
=
self
.
_query_no_local_cache
(
query
)
self
.
_cache_locally
(
etag
,
key
,
result
)
self
.
_cache_locally
(
etag
,
key
,
result
)
return
result
return
result
def
_query_no_local_cache
(
self
,
query
):
def
_query_no_local_cache
(
self
,
query
):
t1
=
time
.
time
()
t1
=
time
.
time
()
result
=
self
.
_caosdb
.
execute_query
(
query
)
query
=
self
.
_caosdb
.
Query
(
q
=
query
)
result
=
query
.
execute
()
etag
=
query
.
etag
t2
=
time
.
time
()
t2
=
time
.
time
()
LOGGER
.
debug
(
"
[%s] execute_query(%s) - %s
"
,
str
(
t1
),
query
,
str
(
t2
-
t1
))
LOGGER
.
debug
(
"
[%s] execute_query(%s) - %s
"
,
str
(
t1
),
query
,
str
(
t2
-
t1
))
return
result
return
result
,
etag
def
_find
(
self
,
record_type
,
*
args
,
**
kwargs
):
def
_find
(
self
,
record_type
,
*
args
,
**
kwargs
):
filter_clause
=
""
filter_clause
=
""
...
...
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