Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hippocampus
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Pascal Jürgens
hippocampus
Commits
d7e0716d
Commit
d7e0716d
authored
1 year ago
by
Pascal Jürgens
Browse files
Options
Downloads
Patches
Plain Diff
Allow multiple dbs in same project
parent
5154656c
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
hippocampus/__init__.py
+11
-10
11 additions, 10 deletions
hippocampus/__init__.py
pyproject.toml
+1
-1
1 addition, 1 deletion
pyproject.toml
with
12 additions
and
11 deletions
hippocampus/__init__.py
+
11
−
10
View file @
d7e0716d
...
...
@@ -13,7 +13,7 @@ from pip._internal.utils.appdirs import user_cache_dir
from
peewee
import
*
from
playhouse.sqlite_ext
import
*
db
=
None
db
s
=
{}
def
setup_db
(
db_path
=
None
):
...
...
@@ -21,13 +21,15 @@ def setup_db(db_path=None):
cache_dir
.
mkdir
(
exist_ok
=
True
,
parents
=
True
)
db_path
=
db_path
or
(
cache_dir
/
'
db.sqlite3
'
)
global
db
global
dbs
if
not
dbs
.
get
(
db_path
):
db
=
SqliteDatabase
(
db_path
,
pragmas
=
{
'
journal_mode
'
:
'
wal
'
,
'
cache_size
'
:
-
1024
*
1000
})
with
db
.
bind_ctx
([
MemoizedCall
]):
MemoizedCall
.
create_table
(
True
)
return
db
dbs
[
db_path
]
=
db
return
dbs
[
db_path
]
class
MemoizedCall
(
Model
):
...
...
@@ -96,8 +98,7 @@ def memoize(remember="forever",
"""
def
decorator
(
fn
):
# Code smell, should get rid of global var
global
db
db
=
db
or
setup_db
(
db_path
)
db
=
setup_db
(
db_path
)
@functools.wraps
(
fn
)
def
inner
(
*
args
,
**
kwargs
):
...
...
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
1
View file @
d7e0716d
[tool.poetry]
name
=
"hippocampus"
version
=
"0.1.
2
"
version
=
"0.1.
4
"
description
=
"simple memoization with sqlite3 and expiry"
authors
=
[
"Pascal Jürgens <juergens@uni-trier.de>"
]
readme
=
"README.md"
...
...
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