Add logging for deleted prekeys and other records
Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
parent
0c896ca1f2
commit
ba0fa4904b
6 changed files with 213 additions and 51 deletions
|
@ -428,27 +428,27 @@ export type DataInterface = {
|
|||
removeDB: () => Promise<void>;
|
||||
removeIndexedDBFiles: () => Promise<void>;
|
||||
|
||||
removeIdentityKeyById: (id: IdentityKeyIdType) => Promise<void>;
|
||||
removeAllIdentityKeys: () => Promise<void>;
|
||||
removeIdentityKeyById: (id: IdentityKeyIdType) => Promise<number>;
|
||||
removeAllIdentityKeys: () => Promise<number>;
|
||||
|
||||
removeKyberPreKeyById: (
|
||||
id: PreKeyIdType | Array<PreKeyIdType>
|
||||
) => Promise<void>;
|
||||
) => Promise<number>;
|
||||
removeKyberPreKeysByServiceId: (serviceId: ServiceIdString) => Promise<void>;
|
||||
removeAllKyberPreKeys: () => Promise<void>;
|
||||
removeAllKyberPreKeys: () => Promise<number>;
|
||||
|
||||
removePreKeyById: (id: PreKeyIdType | Array<PreKeyIdType>) => Promise<void>;
|
||||
removePreKeyById: (id: PreKeyIdType | Array<PreKeyIdType>) => Promise<number>;
|
||||
removePreKeysByServiceId: (serviceId: ServiceIdString) => Promise<void>;
|
||||
removeAllPreKeys: () => Promise<void>;
|
||||
removeAllPreKeys: () => Promise<number>;
|
||||
|
||||
removeSignedPreKeyById: (
|
||||
id: SignedPreKeyIdType | Array<SignedPreKeyIdType>
|
||||
) => Promise<void>;
|
||||
) => Promise<number>;
|
||||
removeSignedPreKeysByServiceId: (serviceId: ServiceIdString) => Promise<void>;
|
||||
removeAllSignedPreKeys: () => Promise<void>;
|
||||
removeAllSignedPreKeys: () => Promise<number>;
|
||||
|
||||
removeAllItems: () => Promise<void>;
|
||||
removeItemById: (id: ItemKeyType | Array<ItemKeyType>) => Promise<void>;
|
||||
removeAllItems: () => Promise<number>;
|
||||
removeItemById: (id: ItemKeyType | Array<ItemKeyType>) => Promise<number>;
|
||||
|
||||
createOrUpdateSenderKey: (key: SenderKeyType) => Promise<void>;
|
||||
getSenderKeyById: (id: SenderKeyIdType) => Promise<SenderKeyType | undefined>;
|
||||
|
@ -494,10 +494,10 @@ export type DataInterface = {
|
|||
unprocessed: Array<UnprocessedType>;
|
||||
}): Promise<void>;
|
||||
bulkAddSessions: (array: Array<SessionType>) => Promise<void>;
|
||||
removeSessionById: (id: SessionIdType) => Promise<void>;
|
||||
removeSessionById: (id: SessionIdType) => Promise<number>;
|
||||
removeSessionsByConversation: (conversationId: string) => Promise<void>;
|
||||
removeSessionsByServiceId: (serviceId: ServiceIdString) => Promise<void>;
|
||||
removeAllSessions: () => Promise<void>;
|
||||
removeAllSessions: () => Promise<number>;
|
||||
getAllSessions: () => Promise<Array<SessionType>>;
|
||||
|
||||
getConversationCount: () => Promise<number>;
|
||||
|
@ -704,8 +704,8 @@ export type DataInterface = {
|
|||
id: string,
|
||||
pending: boolean
|
||||
) => Promise<void>;
|
||||
removeAttachmentDownloadJob: (id: string) => Promise<void>;
|
||||
removeAllAttachmentDownloadJobs: () => Promise<void>;
|
||||
removeAttachmentDownloadJob: (id: string) => Promise<number>;
|
||||
removeAllAttachmentDownloadJobs: () => Promise<number>;
|
||||
|
||||
createOrUpdateStickerPack: (pack: StickerPackType) => Promise<void>;
|
||||
updateStickerPackStatus: (
|
||||
|
|
|
@ -742,10 +742,10 @@ async function bulkAddIdentityKeys(
|
|||
): Promise<void> {
|
||||
return bulkAdd(await getWritableInstance(), IDENTITY_KEYS_TABLE, array);
|
||||
}
|
||||
async function removeIdentityKeyById(id: IdentityKeyIdType): Promise<void> {
|
||||
async function removeIdentityKeyById(id: IdentityKeyIdType): Promise<number> {
|
||||
return removeById(await getWritableInstance(), IDENTITY_KEYS_TABLE, id);
|
||||
}
|
||||
async function removeAllIdentityKeys(): Promise<void> {
|
||||
async function removeAllIdentityKeys(): Promise<number> {
|
||||
return removeAllFromTable(await getWritableInstance(), IDENTITY_KEYS_TABLE);
|
||||
}
|
||||
async function getAllIdentityKeys(): Promise<Array<StoredIdentityKeyType>> {
|
||||
|
@ -774,7 +774,7 @@ async function bulkAddKyberPreKeys(
|
|||
}
|
||||
async function removeKyberPreKeyById(
|
||||
id: PreKeyIdType | Array<PreKeyIdType>
|
||||
): Promise<void> {
|
||||
): Promise<number> {
|
||||
return removeById(await getWritableInstance(), KYBER_PRE_KEYS_TABLE, id);
|
||||
}
|
||||
async function removeKyberPreKeysByServiceId(
|
||||
|
@ -787,7 +787,7 @@ async function removeKyberPreKeysByServiceId(
|
|||
serviceId,
|
||||
});
|
||||
}
|
||||
async function removeAllKyberPreKeys(): Promise<void> {
|
||||
async function removeAllKyberPreKeys(): Promise<number> {
|
||||
return removeAllFromTable(await getWritableInstance(), KYBER_PRE_KEYS_TABLE);
|
||||
}
|
||||
async function getAllKyberPreKeys(): Promise<Array<StoredKyberPreKeyType>> {
|
||||
|
@ -808,7 +808,7 @@ async function bulkAddPreKeys(array: Array<StoredPreKeyType>): Promise<void> {
|
|||
}
|
||||
async function removePreKeyById(
|
||||
id: PreKeyIdType | Array<PreKeyIdType>
|
||||
): Promise<void> {
|
||||
): Promise<number> {
|
||||
return removeById(await getWritableInstance(), PRE_KEYS_TABLE, id);
|
||||
}
|
||||
async function removePreKeysByServiceId(
|
||||
|
@ -821,7 +821,7 @@ async function removePreKeysByServiceId(
|
|||
serviceId,
|
||||
});
|
||||
}
|
||||
async function removeAllPreKeys(): Promise<void> {
|
||||
async function removeAllPreKeys(): Promise<number> {
|
||||
return removeAllFromTable(await getWritableInstance(), PRE_KEYS_TABLE);
|
||||
}
|
||||
async function getAllPreKeys(): Promise<Array<StoredPreKeyType>> {
|
||||
|
@ -850,7 +850,7 @@ async function bulkAddSignedPreKeys(
|
|||
}
|
||||
async function removeSignedPreKeyById(
|
||||
id: SignedPreKeyIdType | Array<SignedPreKeyIdType>
|
||||
): Promise<void> {
|
||||
): Promise<number> {
|
||||
return removeById(await getWritableInstance(), SIGNED_PRE_KEYS_TABLE, id);
|
||||
}
|
||||
async function removeSignedPreKeysByServiceId(
|
||||
|
@ -863,7 +863,7 @@ async function removeSignedPreKeysByServiceId(
|
|||
serviceId,
|
||||
});
|
||||
}
|
||||
async function removeAllSignedPreKeys(): Promise<void> {
|
||||
async function removeAllSignedPreKeys(): Promise<number> {
|
||||
return removeAllFromTable(await getWritableInstance(), SIGNED_PRE_KEYS_TABLE);
|
||||
}
|
||||
async function getAllSignedPreKeys(): Promise<Array<StoredSignedPreKeyType>> {
|
||||
|
@ -912,10 +912,10 @@ async function getAllItems(): Promise<StoredAllItemsType> {
|
|||
}
|
||||
async function removeItemById(
|
||||
id: ItemKeyType | Array<ItemKeyType>
|
||||
): Promise<void> {
|
||||
): Promise<number> {
|
||||
return removeById(await getWritableInstance(), ITEMS_TABLE, id);
|
||||
}
|
||||
async function removeAllItems(): Promise<void> {
|
||||
async function removeAllItems(): Promise<number> {
|
||||
return removeAllFromTable(await getWritableInstance(), ITEMS_TABLE);
|
||||
}
|
||||
|
||||
|
@ -1421,7 +1421,7 @@ async function commitDecryptResult({
|
|||
async function bulkAddSessions(array: Array<SessionType>): Promise<void> {
|
||||
return bulkAdd(await getWritableInstance(), SESSIONS_TABLE, array);
|
||||
}
|
||||
async function removeSessionById(id: SessionIdType): Promise<void> {
|
||||
async function removeSessionById(id: SessionIdType): Promise<number> {
|
||||
return removeById(await getWritableInstance(), SESSIONS_TABLE, id);
|
||||
}
|
||||
async function removeSessionsByConversation(
|
||||
|
@ -1450,7 +1450,7 @@ async function removeSessionsByServiceId(
|
|||
serviceId,
|
||||
});
|
||||
}
|
||||
async function removeAllSessions(): Promise<void> {
|
||||
async function removeAllSessions(): Promise<number> {
|
||||
return removeAllFromTable(await getWritableInstance(), SESSIONS_TABLE);
|
||||
}
|
||||
async function getAllSessions(): Promise<Array<SessionType>> {
|
||||
|
@ -4331,14 +4331,14 @@ async function resetAttachmentDownloadPending(): Promise<void> {
|
|||
`
|
||||
).run();
|
||||
}
|
||||
function removeAttachmentDownloadJobSync(db: Database, id: string): void {
|
||||
function removeAttachmentDownloadJobSync(db: Database, id: string): number {
|
||||
return removeById(db, ATTACHMENT_DOWNLOADS_TABLE, id);
|
||||
}
|
||||
async function removeAttachmentDownloadJob(id: string): Promise<void> {
|
||||
async function removeAttachmentDownloadJob(id: string): Promise<number> {
|
||||
const db = await getWritableInstance();
|
||||
return removeAttachmentDownloadJobSync(db, id);
|
||||
}
|
||||
async function removeAllAttachmentDownloadJobs(): Promise<void> {
|
||||
async function removeAllAttachmentDownloadJobs(): Promise<number> {
|
||||
return removeAllFromTable(
|
||||
await getWritableInstance(),
|
||||
ATTACHMENT_DOWNLOADS_TABLE
|
||||
|
|
|
@ -323,37 +323,39 @@ export function getById<Key extends string | number, Result = unknown>(
|
|||
|
||||
export function removeById<Key extends string | number>(
|
||||
db: Database,
|
||||
table: TableType,
|
||||
tableName: TableType,
|
||||
id: Key | Array<Key>
|
||||
): void {
|
||||
): number {
|
||||
const table = sqlConstant(tableName);
|
||||
if (!Array.isArray(id)) {
|
||||
db.prepare<Query>(
|
||||
`
|
||||
const [query, params] = sql`
|
||||
DELETE FROM ${table}
|
||||
WHERE id = $id;
|
||||
`
|
||||
).run({ id });
|
||||
return;
|
||||
WHERE id = ${id};
|
||||
`;
|
||||
return db.prepare(query).run(params).changes;
|
||||
}
|
||||
|
||||
if (!id.length) {
|
||||
throw new Error('removeById: No ids to delete!');
|
||||
}
|
||||
|
||||
let totalChanges = 0;
|
||||
|
||||
const removeByIdsSync = (ids: ReadonlyArray<string | number>): void => {
|
||||
db.prepare<ArrayQuery>(
|
||||
`
|
||||
const [query, params] = sql`
|
||||
DELETE FROM ${table}
|
||||
WHERE id IN ( ${id.map(() => '?').join(', ')} );
|
||||
`
|
||||
).run(ids);
|
||||
WHERE id IN (${sqlJoin(ids, ', ')});
|
||||
`;
|
||||
totalChanges += db.prepare(query).run(params).changes;
|
||||
};
|
||||
|
||||
batchMultiVarQuery(db, id, removeByIdsSync);
|
||||
|
||||
return totalChanges;
|
||||
}
|
||||
|
||||
export function removeAllFromTable(db: Database, table: TableType): void {
|
||||
db.prepare<EmptyQuery>(`DELETE FROM ${table};`).run();
|
||||
export function removeAllFromTable(db: Database, table: TableType): number {
|
||||
return db.prepare<EmptyQuery>(`DELETE FROM ${table};`).run().changes;
|
||||
}
|
||||
|
||||
export function getAllFromTable<T>(db: Database, table: TableType): Array<T> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue