Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
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
Maunium
synapse
Commits
077d2003
Commit
077d2003
authored
10 years ago
by
Paul "LeoNerd" Evans
Browse files
Options
Downloads
Patches
Plain Diff
Move @cached decorator out into synapse.storage._base; add minimal docs
parent
61959928
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
synapse/storage/_base.py
+35
-0
35 additions, 0 deletions
synapse/storage/_base.py
synapse/storage/roommember.py
+1
-27
1 addition, 27 deletions
synapse/storage/roommember.py
with
36 additions
and
27 deletions
synapse/storage/_base.py
+
35
−
0
View file @
077d2003
...
@@ -35,6 +35,41 @@ sql_logger = logging.getLogger("synapse.storage.SQL")
...
@@ -35,6 +35,41 @@ sql_logger = logging.getLogger("synapse.storage.SQL")
transaction_logger
=
logging
.
getLogger
(
"
synapse.storage.txn
"
)
transaction_logger
=
logging
.
getLogger
(
"
synapse.storage.txn
"
)
# TODO(paul):
# * Move this somewhere higher-level, shared;
# * more generic key management
# * export monitoring stats
# * maximum size; just evict things at random, or consider LRU?
def
cached
(
orig
):
"""
A method decorator that applies a memoizing cache around the function.
The function is presumed to take one additional argument, which is used as
the key for the cache. Cache hits are served directly from the cache;
misses use the function body to generate the value.
The wrapped function has an additional member, a callable called
"
invalidate
"
. This can be used to remove individual entries from the cache.
"""
cache
=
{}
@defer.inlineCallbacks
def
wrapped
(
self
,
key
):
if
key
in
cache
:
defer
.
returnValue
(
cache
[
key
])
ret
=
yield
orig
(
self
,
key
)
cache
[
key
]
=
ret
;
defer
.
returnValue
(
ret
)
def
invalidate
(
key
):
if
key
in
cache
:
del
cache
[
key
]
wrapped
.
invalidate
=
invalidate
return
wrapped
class
LoggingTransaction
(
object
):
class
LoggingTransaction
(
object
):
"""
An object that almost-transparently proxies for the
'
txn
'
object
"""
An object that almost-transparently proxies for the
'
txn
'
object
passed to the constructor. Adds logging to the .execute() method.
"""
passed to the constructor. Adds logging to the .execute() method.
"""
...
...
This diff is collapsed.
Click to expand it.
synapse/storage/roommember.py
+
1
−
27
View file @
077d2003
...
@@ -17,7 +17,7 @@ from twisted.internet import defer
...
@@ -17,7 +17,7 @@ from twisted.internet import defer
from
collections
import
namedtuple
from
collections
import
namedtuple
from
._base
import
SQLBaseStore
from
._base
import
SQLBaseStore
,
cached
from
synapse.api.constants
import
Membership
from
synapse.api.constants
import
Membership
from
synapse.types
import
UserID
from
synapse.types
import
UserID
...
@@ -33,32 +33,6 @@ RoomsForUser = namedtuple(
...
@@ -33,32 +33,6 @@ RoomsForUser = namedtuple(
)
)
# TODO(paul):
# * Move this somewhere higher-level, shared;
# * more generic key management
# * export monitoring stats
# * maximum size; just evict things at random, or consider LRU?
def
cached
(
orig
):
cache
=
{}
@defer.inlineCallbacks
def
wrapped
(
self
,
key
):
if
key
in
cache
:
defer
.
returnValue
(
cache
[
key
])
ret
=
yield
orig
(
self
,
key
)
cache
[
key
]
=
ret
;
defer
.
returnValue
(
ret
)
def
invalidate
(
key
):
if
key
in
cache
:
del
cache
[
key
]
wrapped
.
invalidate
=
invalidate
return
wrapped
class
RoomMemberStore
(
SQLBaseStore
):
class
RoomMemberStore
(
SQLBaseStore
):
def
__init__
(
self
,
*
args
,
**
kw
):
def
__init__
(
self
,
*
args
,
**
kw
):
...
...
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