message: Cache the responses to getNickUserIdMappingForChannel
diff: @@ -21,6 +21,8 @@ const MODES_TO_WATCH = [
  "s"
  ];
  +const NICK_USERID_CACHE_MAX = 512;
  +
  function IrcHandler(ircBridge) {
  this.ircBridge = ircBridge;
  // maintain a map of which user ID is in which PM room, so we know if we
  @@ -50,6 +52,8 @@ function IrcHandler(ircBridge) {
  //'$fromUserId $toUserId' : Promise
  };
  + this.nickUserIdMapCache = new Map(); // server:channel => mapping
  +
  // Map<string,bool> which contains nicks we know have been registered/has display name
  this._registeredNicks = Object.create(null);
  this.getMetrics();
  @@ -468,8 +472,22 @@ IrcHandler.prototype.onMessage = Promise.coroutine(function*(req, server, fromUs
  );
  let mxAction = MatrixAction.fromIrcAction(action);
  + let mapping;
  + if (this.nickUserIdMapCache.has(`${server.domain}:${channel}`)) {
  + mapping = this.nickUserIdMapCache.get(`${server.domain}:${channel}`);
  + }
  + else {
  + mapping = this.ircBridge.getClientPool().getNickUserIdMappingForChannel(
  + server, channel
  + );
  + this.nickUserIdMapCache.set(`${server.domain}:${channel}`, mapping);
  + if (this.nickUserIdMapCache.size > NICK_USERID_CACHE_MAX) {
  + this.nickUserIdMapCache.delete(this.nickUserIdMapCache.keys()[0]);
  + }
  + }
  +
  mxAction.formatMentions(
  - this.ircBridge.getClientPool().getNickUserIdMappingForChannel(server, channel)
  + mapping
  );
  if (!mxAction) {
  @@ -522,6 +540,8 @@ IrcHandler.prototype.onJoin = Promise.coroutine(function*(req, server, joiningUs
  this.incrementMetric("join");
  }
  + this._invalidateNickUserIdMap(server, chan);
  +
  let nick = joiningUser.nick;
  let syncType = kind === "names" ? "initial" : "incremental";
  if (!server.shouldSyncMembershipToMatrix(syncType, chan)) {
  @@ -681,6 +701,7 @@ IrcHandler.prototype.onKick = Promise.coroutine(function*(req, server,
  */
  IrcHandler.prototype.onPart = Promise.coroutine(function*(req, server, leavingUser, chan, kind) {
  this.incrementMetric("part");
  + this._invalidateNickUserIdMap(server, chan);
  // parts are always incremental (only NAMES are initial)
  if (!server.shouldSyncMembershipToMatrix("incremental", chan)) {
  req.log.info("Server doesn't mirror parts.");
  @@ -1006,6 +1027,10 @@ IrcHandler.prototype._setMatrixRoomAsInviteOnly = function(room, isInviteOnly) {
  );
  };
  +IrcHandler.prototype._invalidateNickUserIdMap = function(server, channel) {
  + this.nickUserIdMapCache.delete(`${server.domain}:${channel}`);
  +}
  +
  IrcHandler.prototype.incrementMetric = function(metric) {
  if (this._callCountMetrics[metric] === undefined) {
  this._callCountMetrics[metric] = 0;
  