Improve deduplication script

This commit is contained in:
Will Hunt 2021-12-02 12:37:19 +00:00
parent b6e37947bd
commit 23e00319ff
3 changed files with 9 additions and 3 deletions

View File

@ -44,7 +44,7 @@ export class ConnectionManager {
public push(...connections: IConnection[]) {
// NOTE: Double loop
for (const connection of connections) {
if (!this.connections.find((c) => c === connection)) {
if (!this.connections.find(c => c.connectionId === connection.connectionId)) {
this.connections.push(connection);
}
}
@ -204,7 +204,7 @@ export class ConnectionManager {
const connections: IConnection[] = [];
for (const event of state) {
const conn = await this.createConnectionForState(roomId, new StateEvent(event));
if (conn) { connections.push(conn); }
if (conn) { this.push(conn); }
}
return connections;
}

View File

@ -12,6 +12,6 @@ export abstract class BaseConnection {
}
public get connectionId(): string {
return FormatUtil.hashId(`${this.canonicalStateType}/${this.stateKey}`);
return FormatUtil.hashId(`${this.roomId}/${this.canonicalStateType}/${this.stateKey}`);
}
}

View File

@ -3,8 +3,14 @@ import { IssuesOpenedEvent, IssuesEditedEvent } from "@octokit/webhooks-types";
import { GetConnectionsResponseItem } from "../provisioning/api";
export interface IConnection {
/**
* The roomId that this connection serves.
*/
roomId: string;
/**
* The unique connection ID. This is a opaque hash of the roomId, connection type and state key.
*/
get connectionId(): string;
/**
* When a room gets an update to it's state.