Set the service ID as soon as it is known.

This commit is contained in:
Kegan Dougal 2015-03-16 15:24:32 +00:00
parent d04fa1f712
commit f0d6f724a2
2 changed files with 5 additions and 4 deletions

View file

@ -59,13 +59,13 @@ class ApplicationServicesHandler(object):
) )
if not stored_service: if not stored_service:
raise StoreError(404, "Application service not found") raise StoreError(404, "Application service not found")
app_service.id = stored_service.id
except StoreError: except StoreError:
raise SynapseError( raise SynapseError(
403, "Unrecognised application services token. " 403, "Unrecognised application services token. "
"Consult the home server admin.", "Consult the home server admin.",
errcode=Codes.FORBIDDEN errcode=Codes.FORBIDDEN
) )
app_service.hs_token = self._generate_hs_token() app_service.hs_token = self._generate_hs_token()
# create a sender for this application service which is used when # create a sender for this application service which is used when

View file

@ -101,11 +101,12 @@ class ApplicationServiceStore(SQLBaseStore):
if not service.hs_token: if not service.hs_token:
raise StoreError(500, "No HS token") raise StoreError(500, "No HS token")
yield self.runInteraction( as_id = yield self.runInteraction(
"update_app_service", "update_app_service",
self._update_app_service_txn, self._update_app_service_txn,
service service
) )
service.id = as_id
# update cache TODO: Should this be in the txn? # update cache TODO: Should this be in the txn?
for (index, cache_service) in enumerate(self.services_cache): for (index, cache_service) in enumerate(self.services_cache):
@ -124,7 +125,7 @@ class ApplicationServiceStore(SQLBaseStore):
"update_app_service_txn: Failed to find as_id for token=", "update_app_service_txn: Failed to find as_id for token=",
service.token service.token
) )
return False return
txn.execute( txn.execute(
"UPDATE application_services SET url=?, hs_token=?, sender=? " "UPDATE application_services SET url=?, hs_token=?, sender=? "
@ -144,7 +145,7 @@ class ApplicationServiceStore(SQLBaseStore):
"as_id, namespace, regex) values(?,?,?)", "as_id, namespace, regex) values(?,?,?)",
(as_id, ns_int, json.dumps(regex_obj)) (as_id, ns_int, json.dumps(regex_obj))
) )
return True return as_id
def _get_as_id_txn(self, txn, token): def _get_as_id_txn(self, txn, token):
cursor = txn.execute( cursor = txn.execute(