Skip to content

Commit

Permalink
Remove 4 unused database functions
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn-Signal authored May 27, 2021
1 parent 05f9224 commit 20e501d
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 77 deletions.
24 changes: 0 additions & 24 deletions ts/sql/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ const dataInterface: ClientInterface = {
createOrUpdateSession,
createOrUpdateSessions,
commitSessionsAndUnprocessed,
getSessionById,
getSessionsById,
bulkAddSessions,
removeSessionById,
removeSessionsByConversation,
Expand Down Expand Up @@ -202,8 +200,6 @@ const dataInterface: ClientInterface = {
getUnprocessedCount,
getAllUnprocessed,
getUnprocessedById,
saveUnprocessed,
saveUnprocesseds,
updateUnprocessedAttempts,
updateUnprocessedWithData,
updateUnprocessedsWithData,
Expand Down Expand Up @@ -778,16 +774,6 @@ async function commitSessionsAndUnprocessed(options: {
}) {
await channels.commitSessionsAndUnprocessed(options);
}
async function getSessionById(id: string) {
const session = await channels.getSessionById(id);

return session;
}
async function getSessionsById(id: string) {
const sessions = await channels.getSessionsById(id);

return sessions;
}
async function bulkAddSessions(array: Array<SessionType>) {
await channels.bulkAddSessions(array);
}
Expand Down Expand Up @@ -1355,16 +1341,6 @@ async function getUnprocessedById(id: string) {
return channels.getUnprocessedById(id);
}

async function saveUnprocessed(data: UnprocessedType) {
const id = await channels.saveUnprocessed(_cleanData(data));

return id;
}

async function saveUnprocesseds(arrayOfUnprocessed: Array<UnprocessedType>) {
await channels.saveUnprocesseds(_cleanData(arrayOfUnprocessed));
}

async function updateUnprocessedAttempts(id: string, attempts: number) {
await channels.updateUnprocessedAttempts(id, attempts);
}
Expand Down
10 changes: 0 additions & 10 deletions ts/sql/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ export type DataInterface = {
sessions: Array<SessionType>;
unprocessed: Array<UnprocessedType>;
}): Promise<void>;
getSessionById: (id: string) => Promise<SessionType | undefined>;
getSessionsById: (conversationId: string) => Promise<Array<SessionType>>;
bulkAddSessions: (array: Array<SessionType>) => Promise<void>;
removeSessionById: (id: string) => Promise<void>;
removeSessionsByConversation: (conversationId: string) => Promise<void>;
Expand Down Expand Up @@ -234,10 +232,6 @@ export type DataInterface = {

getUnprocessedCount: () => Promise<number>;
getAllUnprocessed: () => Promise<Array<UnprocessedType>>;
saveUnprocessed: (
data: UnprocessedType,
options?: { forceSave?: boolean }
) => Promise<string>;
updateUnprocessedAttempts: (id: string, attempts: number) => Promise<void>;
updateUnprocessedWithData: (
id: string,
Expand All @@ -247,10 +241,6 @@ export type DataInterface = {
array: Array<{ id: string; data: UnprocessedUpdateType }>
) => Promise<void>;
getUnprocessedById: (id: string) => Promise<UnprocessedType | undefined>;
saveUnprocesseds: (
arrayOfUnprocessed: Array<UnprocessedType>,
options?: { forceSave?: boolean }
) => Promise<void>;
removeUnprocessed: (id: string | Array<string>) => Promise<void>;
removeAllUnprocessed: () => Promise<void>;

Expand Down
43 changes: 1 addition & 42 deletions ts/sql/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ const dataInterface: ServerInterface = {
createOrUpdateSession,
createOrUpdateSessions,
commitSessionsAndUnprocessed,
getSessionById,
getSessionsById,
bulkAddSessions,
removeSessionById,
removeSessionsByConversation,
Expand Down Expand Up @@ -191,12 +189,10 @@ const dataInterface: ServerInterface = {

getUnprocessedCount,
getAllUnprocessed,
saveUnprocessed,
updateUnprocessedAttempts,
updateUnprocessedWithData,
updateUnprocessedsWithData,
getUnprocessedById,
saveUnprocesseds,
removeUnprocessed,
removeAllUnprocessed,

Expand Down Expand Up @@ -2291,27 +2287,6 @@ async function commitSessionsAndUnprocessed({
})();
}

async function getSessionById(id: string): Promise<SessionType | undefined> {
return getById(SESSIONS_TABLE, id);
}
async function getSessionsById(
conversationId: string
): Promise<Array<SessionType>> {
const db = getInstance();
const rows: JSONRows = db
.prepare<Query>(
`
SELECT json
FROM sessions
WHERE conversationId = $conversationId;
`
)
.all({
conversationId,
});

return rows.map(row => jsonToObject(row.json));
}
function bulkAddSessions(array: Array<SessionType>): Promise<void> {
return bulkAdd(SESSIONS_TABLE, array);
}
Expand Down Expand Up @@ -4041,7 +4016,7 @@ function saveUnprocessedSync(data: UnprocessedType): string {
decrypted,
} = data;
if (!id) {
throw new Error('saveUnprocessed: id was falsey');
throw new Error('saveUnprocessedSync: id was falsey');
}

prepare(
Expand Down Expand Up @@ -4087,22 +4062,6 @@ function saveUnprocessedSync(data: UnprocessedType): string {
return id;
}

async function saveUnprocessed(data: UnprocessedType): Promise<string> {
return saveUnprocessedSync(data);
}

async function saveUnprocesseds(
arrayOfUnprocessed: Array<UnprocessedType>
): Promise<void> {
const db = getInstance();

db.transaction(() => {
for (const unprocessed of arrayOfUnprocessed) {
assertSync(saveUnprocessedSync(unprocessed));
}
})();
}

async function updateUnprocessedAttempts(
id: string,
attempts: number
Expand Down
2 changes: 1 addition & 1 deletion ts/test-electron/SignalProtocolStore_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ describe('SignalProtocolStore', () => {
assert.strictEqual(items[2].envelope, 'third');
});

it('saveUnprocessed successfully updates item', async () => {
it('can updates items', async () => {
const id = '1-one';
await store.addUnprocessed({
id,
Expand Down

0 comments on commit 20e501d

Please sign in to comment.