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
Package registry
Container Registry
Model registry
Operate
Terraform modules
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
Timo Ley
synapse
Commits
db7283cc
Commit
db7283cc
authored
8 years ago
by
Paul "LeoNerd" Evans
Browse files
Options
Downloads
Patches
Plain Diff
Implement a ResponseCache around 3PE lookup metadata lookups
parent
d0b8d49f
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
synapse/appservice/api.py
+21
-11
21 additions, 11 deletions
synapse/appservice/api.py
with
21 additions
and
11 deletions
synapse/appservice/api.py
+
21
−
11
View file @
db7283cc
...
...
@@ -17,6 +17,7 @@ from twisted.internet import defer
from
synapse.api.errors
import
CodeMessageException
from
synapse.http.client
import
SimpleHttpClient
from
synapse.events.utils
import
serialize_event
from
synapse.util.caches.response_cache
import
ResponseCache
from
synapse.types
import
ThirdPartyEntityKind
import
logging
...
...
@@ -25,6 +26,9 @@ import urllib
logger
=
logging
.
getLogger
(
__name__
)
HOUR_IN_MS
=
60
*
60
*
1000
def
_is_valid_3pe_result
(
r
,
field
):
if
not
isinstance
(
r
,
dict
):
return
False
...
...
@@ -56,6 +60,8 @@ class ApplicationServiceApi(SimpleHttpClient):
super
(
ApplicationServiceApi
,
self
).
__init__
(
hs
)
self
.
clock
=
hs
.
get_clock
()
self
.
protocol_meta_cache
=
ResponseCache
(
hs
,
timeout_ms
=
1
*
HOUR_IN_MS
)
@defer.inlineCallbacks
def
query_user
(
self
,
service
,
user_id
):
uri
=
service
.
url
+
(
"
/users/%s
"
%
urllib
.
quote
(
user_id
))
...
...
@@ -131,18 +137,22 @@ class ApplicationServiceApi(SimpleHttpClient):
logger
.
warning
(
"
query_3pe to %s threw exception %s
"
,
uri
,
ex
)
defer
.
returnValue
([])
@defer.inlineCallbacks
def
get_3pe_protocol
(
self
,
service
,
protocol
):
# TODO: cache
uri
=
"
%s/thirdparty/protocol/%s
"
%
(
service
.
url
,
urllib
.
quote
(
protocol
))
try
:
response
=
yield
self
.
get_json
(
uri
,
{})
defer
.
returnValue
(
response
)
except
Exception
as
ex
:
logger
.
warning
(
"
query_3pe_protocol to %s threw exception %s
"
,
uri
,
ex
)
defer
.
returnValue
({})
@defer.inlineCallbacks
def
_get
():
uri
=
"
%s/thirdparty/protocol/%s
"
%
(
service
.
url
,
urllib
.
quote
(
protocol
))
try
:
defer
.
returnValue
((
yield
self
.
get_json
(
uri
,
{})))
except
Exception
as
ex
:
logger
.
warning
(
"
query_3pe_protocol to %s threw exception %s
"
,
uri
,
ex
)
defer
.
returnValue
({})
key
=
(
service
.
id
,
protocol
)
return
self
.
protocol_meta_cache
.
get
(
key
)
or
(
self
.
protocol_meta_cache
.
set
(
key
,
_get
())
)
@defer.inlineCallbacks
def
push_bulk
(
self
,
service
,
events
,
txn_id
=
None
):
...
...
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