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
29747a3b
Verified
Commit
29747a3b
authored
4 years ago
by
Timm Fitschen
Browse files
Options
Downloads
Patches
Plain Diff
WIP: local caching
parent
9e48d028
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
djaosdb/caosdb_client.py
+24
-5
24 additions, 5 deletions
djaosdb/caosdb_client.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
with
25 additions
and
6 deletions
djaosdb/caosdb_client.py
+
24
−
5
View file @
29747a3b
...
...
@@ -121,6 +121,8 @@ class DefaultCaosDBClientDelegate:
self
.
_caosdb
=
caosdb
self
.
_caosdb
.
configure_connection
(
**
kwargs
)
self
.
_query_cache
=
{}
self
.
_etag
=
None
def
_get_reference_clause
(
self
,
type
,
p
,
v
,
negation
,
sub
=
None
):
result
=
(
f
"
REFERENCES
{
v
}
"
...
...
@@ -162,7 +164,22 @@ class DefaultCaosDBClientDelegate:
return
f
'
{
n
}{
p
}{
o
}
"
{
v
}
"'
raise
NotImplementedError
(
"
_get_filter_clause(%s)
"
,
fil
)
def
_query
(
self
,
query
):
def
_cache_locally
(
self
,
etag
,
key
,
value
):
if
etag
!=
self
.
_etag
:
self
.
_query_cache
=
{}
if
key
is
not
None
:
self
.
_query_cache
[
key
]
=
value
def
_query
(
self
,
query
,
key
=
None
):
if
key
is
not
None
and
key
in
self
.
query_local_cache
:
return
self
.
_query_cache
[
key
]
result
=
self
.
_query_no_local_cache
(
query
)
self
.
_cache_locally
(
etag
,
key
,
result
)
return
result
def
_query_no_local_cache
(
self
,
query
):
t1
=
time
.
time
()
result
=
self
.
_caosdb
.
execute_query
(
query
)
t2
=
time
.
time
()
...
...
@@ -176,7 +193,7 @@ class DefaultCaosDBClientDelegate:
filter_clause
=
"
WITH
"
+
self
.
_get_filter_clause
(
fil
)
query
=
f
'
FIND RECORD
"
{
record_type
}
"
{
filter_clause
}
'
return
self
.
_query
(
query
)
return
self
.
_query
(
query
,
key
=
query
)
def
_get_property_values
(
self
,
container
,
projection
):
if
projection
is
None
:
...
...
@@ -335,10 +352,10 @@ class DefaultCaosDBClientDelegate:
def
_aggregate
(
self
,
record_type
,
sort
=
None
,
projection
=
None
,
limit
=
None
,
filter
=
None
,
count
=
False
,
skip
=
None
):
query
=
self
.
_generate_query
(
record_type
,
sort
,
projection
,
filter
,
query
,
key
=
self
.
_generate_query
(
record_type
,
sort
,
projection
,
filter
,
count
)
res
=
self
.
_query
(
query
)
res
=
self
.
_query
(
query
,
key
=
key
)
if
count
:
return
CountResult
(
res
,
count
)
rows
=
self
.
_get_property_values
(
res
,
projection
)
...
...
@@ -354,7 +371,9 @@ class DefaultCaosDBClientDelegate:
elif
sort
is
not
None
:
prefix
=
'
SELECT
'
+
"
,
"
.
join
(
list
(
projection
)
+
list
(
sort
.
keys
()))
+
"
FROM
"
return
f
'
{
prefix
}
RECORD
"
{
record_type
}
"
{
filter_clause
}
'
query
=
f
'
{
prefix
}
RECORD
"
{
record_type
}
"
{
filter_clause
}
'
key
=
query
if
not
count
else
None
return
query
,
key
def
delete_many
(
self
,
record_type
,
filter
):
container
=
self
.
_find
(
record_type
,
filter
=
filter
)
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
29747a3b
...
...
@@ -82,7 +82,7 @@ def find_version(*file_paths):
install_requires
=
[
'
sqlparse==0.2.4
'
,
'
caosdb>=0.
4.0
'
,
'
caosdb>=0.
5.1
'
,
'
django>=2.1
'
,
'
python-dateutil>=2.8.1
'
,
]
...
...
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