Put a cache on get_aliases_for_room

This commit is contained in:
Paul "LeoNerd" Evans 2015-03-20 19:21:13 +00:00
parent a63b4f7101
commit 72d8406409

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from ._base import SQLBaseStore from ._base import SQLBaseStore, cached
from synapse.api.errors import SynapseError from synapse.api.errors import SynapseError
@ -106,14 +106,19 @@ class DirectoryStore(SQLBaseStore):
}, },
desc="create_room_alias_association", desc="create_room_alias_association",
) )
self.get_aliases_for_room.invalidate(room_id)
@defer.inlineCallbacks
def delete_room_alias(self, room_alias): def delete_room_alias(self, room_alias):
return self.runInteraction( room_id = yield self.runInteraction(
"delete_room_alias", "delete_room_alias",
self._delete_room_alias_txn, self._delete_room_alias_txn,
room_alias, room_alias,
) )
self.get_aliases_for_room.invalidate(room_id)
defer.returnValue(room_id)
def _delete_room_alias_txn(self, txn, room_alias): def _delete_room_alias_txn(self, txn, room_alias):
cursor = txn.execute( cursor = txn.execute(
"SELECT room_id FROM room_aliases WHERE room_alias = ?", "SELECT room_id FROM room_aliases WHERE room_alias = ?",
@ -138,6 +143,7 @@ class DirectoryStore(SQLBaseStore):
return room_id return room_id
@cached()
def get_aliases_for_room(self, room_id): def get_aliases_for_room(self, room_id):
return self._simple_select_onecol( return self._simple_select_onecol(
"room_aliases", "room_aliases",