Skip to content
Extraits de code Groupes Projets
Valider 5f245e1c rédigé par Will Hunt's avatar Will Hunt
Parcourir les fichiers

Store prefixes

parent 641edc7d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -156,10 +156,10 @@ export class DbRoomStore { ...@@ -156,10 +156,10 @@ export class DbRoomStore {
public async getEntriesByMatrixId(matrixId: string): Promise<IRoomStoreEntry[]> { public async getEntriesByMatrixId(matrixId: string): Promise<IRoomStoreEntry[]> {
const cached = this.entriesMatrixIdCache.get(matrixId); const cached = this.entriesMatrixIdCache.get(matrixId);
if (cached && cached.ts + ENTRY_CACHE_LIMETIME > Date.now()) { if (cached && cached.ts + ENTRY_CACHE_LIMETIME > Date.now()) {
MetricPeg.get.storeCall("getEntriesByMatrixId", true); MetricPeg.get.storeCall("RoomStore.getEntriesByMatrixId", true);
return cached.e; return cached.e;
} }
MetricPeg.get.storeCall("getEntriesByMatrixId", false); MetricPeg.get.storeCall("RoomStore.getEntriesByMatrixId", false);
const entries = await this.db.All( const entries = await this.db.All(
"SELECT * FROM room_entries WHERE matrix_id = $id", {id: matrixId}, "SELECT * FROM room_entries WHERE matrix_id = $id", {id: matrixId},
); );
...@@ -193,7 +193,7 @@ export class DbRoomStore { ...@@ -193,7 +193,7 @@ export class DbRoomStore {
} }
public async getEntriesByMatrixIds(matrixIds: string[]): Promise<IRoomStoreEntry[]> { public async getEntriesByMatrixIds(matrixIds: string[]): Promise<IRoomStoreEntry[]> {
MetricPeg.get.storeCall("getEntriesByMatrixIds", false); MetricPeg.get.storeCall("RoomStore.getEntriesByMatrixIds", false);
const mxIdMap = { }; const mxIdMap = { };
matrixIds.forEach((mxId, i) => mxIdMap[i] = mxId); matrixIds.forEach((mxId, i) => mxIdMap[i] = mxId);
const sql = `SELECT * FROM room_entries WHERE matrix_id IN (${matrixIds.map((_, id) => `\$${id}`).join(", ")})`; const sql = `SELECT * FROM room_entries WHERE matrix_id IN (${matrixIds.map((_, id) => `\$${id}`).join(", ")})`;
...@@ -226,7 +226,7 @@ export class DbRoomStore { ...@@ -226,7 +226,7 @@ export class DbRoomStore {
} }
public async linkRooms(matrixRoom: MatrixStoreRoom, remoteRoom: RemoteStoreRoom) { public async linkRooms(matrixRoom: MatrixStoreRoom, remoteRoom: RemoteStoreRoom) {
MetricPeg.get.storeCall("linkRooms", false); MetricPeg.get.storeCall("RoomStore.linkRooms", false);
await this.upsertRoom(remoteRoom); await this.upsertRoom(remoteRoom);
const values = { const values = {
...@@ -249,7 +249,7 @@ export class DbRoomStore { ...@@ -249,7 +249,7 @@ export class DbRoomStore {
} }
public async getEntriesByRemoteRoomData(data: IRemoteRoomDataLazy): Promise<IRoomStoreEntry[]> { public async getEntriesByRemoteRoomData(data: IRemoteRoomDataLazy): Promise<IRoomStoreEntry[]> {
MetricPeg.get.storeCall("getEntriesByRemoteRoomData", false); MetricPeg.get.storeCall("RoomStore.getEntriesByRemoteRoomData", false);
Object.keys(data).filter((k) => typeof(data[k]) === "boolean").forEach((k) => { Object.keys(data).filter((k) => typeof(data[k]) === "boolean").forEach((k) => {
data[k] = Number(data[k]); data[k] = Number(data[k]);
}); });
...@@ -276,13 +276,13 @@ export class DbRoomStore { ...@@ -276,13 +276,13 @@ export class DbRoomStore {
} }
public async removeEntriesByRemoteRoomId(remoteId: string) { public async removeEntriesByRemoteRoomId(remoteId: string) {
MetricPeg.get.storeCall("removeEntriesByRemoteRoomId", false); MetricPeg.get.storeCall("RoomStore.removeEntriesByRemoteRoomId", false);
await this.db.Run(`DELETE FROM room_entries WHERE remote_id = $remoteId`, {remoteId}); await this.db.Run(`DELETE FROM room_entries WHERE remote_id = $remoteId`, {remoteId});
await this.db.Run(`DELETE FROM remote_room_data WHERE room_id = $remoteId`, {remoteId}); await this.db.Run(`DELETE FROM remote_room_data WHERE room_id = $remoteId`, {remoteId});
} }
public async removeEntriesByMatrixRoomId(matrixId: string) { public async removeEntriesByMatrixRoomId(matrixId: string) {
MetricPeg.get.storeCall("removeEntriesByMatrixRoomId", false); MetricPeg.get.storeCall("RoomStore.removeEntriesByMatrixRoomId", false);
const entries = (await this.db.All(`SELECT * FROM room_entries WHERE matrix_id = $matrixId`, {matrixId})) || []; const entries = (await this.db.All(`SELECT * FROM room_entries WHERE matrix_id = $matrixId`, {matrixId})) || [];
await Util.AsyncForEach(entries, async (entry) => { await Util.AsyncForEach(entries, async (entry) => {
if (entry.remote_id) { if (entry.remote_id) {
...@@ -294,7 +294,7 @@ export class DbRoomStore { ...@@ -294,7 +294,7 @@ export class DbRoomStore {
} }
private async upsertRoom(room: RemoteStoreRoom) { private async upsertRoom(room: RemoteStoreRoom) {
MetricPeg.get.storeCall("upsertRoom", false); MetricPeg.get.storeCall("RoomStore.upsertRoom", false);
if (!room.data) { if (!room.data) {
throw new Error("Tried to upsert a room with undefined data"); throw new Error("Tried to upsert a room with undefined data");
} }
......
...@@ -54,10 +54,10 @@ export class DbUserStore { ...@@ -54,10 +54,10 @@ export class DbUserStore {
public async getRemoteUser(remoteId: string): Promise<RemoteUser|null> { public async getRemoteUser(remoteId: string): Promise<RemoteUser|null> {
const cached = this.remoteUserCache.get(remoteId); const cached = this.remoteUserCache.get(remoteId);
if (cached && cached.ts + ENTRY_CACHE_LIMETIME > Date.now()) { if (cached && cached.ts + ENTRY_CACHE_LIMETIME > Date.now()) {
MetricPeg.get.storeCall("getRemoteUser", true); MetricPeg.get.storeCall("UserStore.getRemoteUser", true);
return cached.e; return cached.e;
} }
MetricPeg.get.storeCall("getRemoteUser", false); MetricPeg.get.storeCall("UserStore.getRemoteUser", false);
const row = await this.db.Get( const row = await this.db.Get(
"SELECT * FROM user_entries WHERE remote_id = $id", {id: remoteId}, "SELECT * FROM user_entries WHERE remote_id = $id", {id: remoteId},
...@@ -89,7 +89,7 @@ export class DbUserStore { ...@@ -89,7 +89,7 @@ export class DbUserStore {
} }
public async setRemoteUser(user: RemoteUser) { public async setRemoteUser(user: RemoteUser) {
MetricPeg.get.storeCall("setRemoteUser", false); MetricPeg.get.storeCall("UserStore.setRemoteUser", false);
this.remoteUserCache.delete(user.id); this.remoteUserCache.delete(user.id);
const existingData = await this.db.Get( const existingData = await this.db.Get(
"SELECT * FROM remote_user_data WHERE remote_id = $remoteId", "SELECT * FROM remote_user_data WHERE remote_id = $remoteId",
...@@ -160,7 +160,7 @@ AND guild_id = $guild_id`, ...@@ -160,7 +160,7 @@ AND guild_id = $guild_id`,
} }
public async linkUsers(matrixId: string, remoteId: string) { public async linkUsers(matrixId: string, remoteId: string) {
MetricPeg.get.storeCall("linkUsers", false); MetricPeg.get.storeCall("UserStore.linkUsers", false);
// This is used ONCE in the bridge to link two IDs, so do not UPSURT data. // This is used ONCE in the bridge to link two IDs, so do not UPSURT data.
try { try {
await this.db.Run(`INSERT INTO user_entries VALUES ($matrixId, $remoteId)`, { await this.db.Run(`INSERT INTO user_entries VALUES ($matrixId, $remoteId)`, {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter