message: Use a LRU for the nick mappings
diff: @@ -28,8 +28,11 @@ import { Ipv6Generator } from "./Ipv6Generator";
  import { IrcEventBroker } from "./IrcEventBroker";
  import { DataStore } from "../datastore/DataStore";
  import { Gauge } from "prom-client";
  +import QuickLRU from "quick-lru";
  const log = getLogger("ClientPool");
  +const NICK_CACHE_SIZE = 256;
  +
  interface ReconnectionItem {
  cli: BridgedClient;
  chanList: string[];
  @@ -42,7 +45,7 @@ interface ReconnectionItem {
  export class ClientPool {
  private botClients: Map<string, BridgedClient>;
  private virtualClients: { [serverDomain: string]: {
  - nicks: Map<string, BridgedClient>;
  + nicks: QuickLRU<string, BridgedClient>;
  userIds: Map<string, BridgedClient>;
  pending: Map<string, BridgedClient>;
  };};
  @@ -279,7 +282,7 @@ export class ClientPool {
  if (this.virtualClients[server.domain] === undefined) {
  this.virtualClients[server.domain] = {
  - nicks: new Map(),
  + nicks: new QuickLRU({maxSize: NICK_CACHE_SIZE}),
  userIds: new Map(),
  pending: new Map(),
  };
  @@ -345,11 +348,21 @@ export class ClientPool {
  return bot;
  }
  - if (!this.virtualClients[server.domain]) {
  + const serverSet = this.virtualClients[server.domain];
  +
  + if (!serverSet) {
  return undefined;
  }
  - const cli = this.virtualClients[server.domain].nicks.get(nick);
  - if (cli?.isDead()) {
  +
  + let cli = serverSet.nicks.get(nick);
  + if (!cli) {
  + cli = [...serverSet.userIds.values()].find(c => c.nick === nick);
  + if (!cli) {
  + return undefined;
  + }
  + serverSet.nicks.set(cli.nick, cli);
  + }
  +
  return undefined;
  }
  return cli;
  @@ -412,7 +425,7 @@ export class ClientPool {
  // find the oldest client to kill.
  let oldest: BridgedClient|null = null;
  - for (const client of this.virtualClients[server.domain].nicks.values()) {
  + for (const client of this.virtualClients[server.domain].userIds.values()) {
  if (!client) {
  // possible since undefined/null values can be present from culled entries
  continue;
  @@ -420,6 +433,9 @@ export class ClientPool {
  if (client.isBot) {
  continue; // don't ever kick the bot off.
  }
  + if (client.status !== BridgedClientStatus.CONNECTED) {
  + continue; // Don't kick clients that aren't connected.
  + }
  if (oldest === null) {
  oldest = client;
  continue;
  