Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3350687
D4834.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D4834.diff
View Options
diff --git a/keyserver/src/fetchers/message-fetchers.js b/keyserver/src/fetchers/message-fetchers.js
--- a/keyserver/src/fetchers/message-fetchers.js
+++ b/keyserver/src/fetchers/message-fetchers.js
@@ -31,7 +31,6 @@
mergeOrConditions,
mergeAndConditions,
} from '../database/database';
-import { getDBType } from '../database/db-config';
import type { SQLStatementType } from '../database/types';
import type { PushInfo } from '../push/send';
import type { Viewer } from '../session/viewer';
@@ -130,13 +129,8 @@
}
const derivedMessages = await fetchDerivedMessages(collapseResult);
-
- const parsePromises = [...rowsByUser.values()].map(userRows =>
- parseMessageSQLResult(userRows, derivedMessages),
- );
- const parsedMessages = await Promise.all(parsePromises);
-
- for (const messages of parsedMessages) {
+ for (const userRows of rowsByUser.values()) {
+ const messages = parseMessageSQLResult(userRows, derivedMessages);
for (const message of messages) {
const { rawMessageInfo, rows } = message;
const [row] = rows;
@@ -164,14 +158,14 @@
rawMessageInfo: RawMessageInfo,
rows: $ReadOnlyArray<Object>,
}>;
-async function parseMessageSQLResult(
+function parseMessageSQLResult(
rows: $ReadOnlyArray<Object>,
derivedMessages: $ReadOnlyMap<
string,
RawComposableMessageInfo | RawRobotextMessageInfo,
>,
viewer?: Viewer,
-): Promise<MessageSQLResult> {
+): MessageSQLResult {
const rowsByID = new Map();
for (const row of rows) {
const id = row.id.toString();
@@ -183,16 +177,19 @@
}
}
- const messagePromises = [...rowsByID.values()].map(async messageRows => {
- const rawMessageInfo = await rawMessageInfoFromRows(
+ const messages = [];
+ for (const messageRows of rowsByID.values()) {
+ const rawMessageInfo = rawMessageInfoFromRows(
messageRows,
viewer,
derivedMessages,
);
- return rawMessageInfo ? { rawMessageInfo, rows: messageRows } : null;
- });
- const messages = await Promise.all(messagePromises);
- return messages.filter(Boolean);
+ if (rawMessageInfo) {
+ messages.push({ rawMessageInfo, rows: messageRows });
+ }
+ }
+
+ return messages;
}
function assertSingleRow(rows: $ReadOnlyArray<Object>): Object {
@@ -214,30 +211,24 @@
return assertMessageType(rows[0].type);
}
-async function rawMessageInfoFromRows(
+function rawMessageInfoFromRows(
rawRows: $ReadOnlyArray<Object>,
viewer?: Viewer,
derivedMessages: $ReadOnlyMap<
string,
RawComposableMessageInfo | RawRobotextMessageInfo,
>,
-): Promise<?RawMessageInfo> {
- let rows = rawRows;
- const dbType = await getDBType();
- if (dbType !== 'mysql5.7') {
- rows = rawRows.map(row => ({
- ...row,
- subthread_permissions: JSON.parse(row.subthread_permissions),
- }));
- }
+): ?RawMessageInfo {
+ const rows = rawRows.map(row => ({
+ ...row,
+ subthread_permissions: JSON.parse(row.subthread_permissions),
+ }));
const type = mostRecentRowType(rows);
const messageSpec = messageSpecs[type];
if (type === messageTypes.IMAGES || type === messageTypes.MULTIMEDIA) {
- const media = await Promise.all(
- rows.filter(row => row.uploadID).map(mediaFromRow),
- );
+ const media = rows.filter(row => row.uploadID).map(mediaFromRow);
const [row] = rows;
const localID = localIDFromCreationString(viewer, row.creation);
invariant(
@@ -618,7 +609,7 @@
return null;
}
const derivedMessages = await fetchDerivedMessages(result, viewer);
- return await rawMessageInfoFromRows(result, viewer, derivedMessages);
+ return rawMessageInfoFromRows(result, viewer, derivedMessages);
}
const entryIDExtractString = '$.entryID';
@@ -647,7 +638,7 @@
return null;
}
const derivedMessages = await fetchDerivedMessages(result, viewer);
- return await rawMessageInfoFromRows(result, viewer, derivedMessages);
+ return rawMessageInfoFromRows(result, viewer, derivedMessages);
}
async function fetchMessageRowsByIDs(messageIDs: $ReadOnlyArray<string>) {
@@ -713,7 +704,7 @@
return null;
}
const derivedMessages = await fetchDerivedMessages(result, viewer);
- return await rawMessageInfoFromRows(result, viewer, derivedMessages);
+ return rawMessageInfoFromRows(result, viewer, derivedMessages);
}
export {
diff --git a/keyserver/src/fetchers/upload-fetchers.js b/keyserver/src/fetchers/upload-fetchers.js
--- a/keyserver/src/fetchers/upload-fetchers.js
+++ b/keyserver/src/fetchers/upload-fetchers.js
@@ -4,7 +4,6 @@
import { ServerError } from 'lib/utils/errors';
import { dbQuery, SQL } from '../database/database';
-import { getDBType } from '../database/db-config';
import type { Viewer } from '../session/viewer';
import { getAndAssertCommAppURLFacts } from '../utils/urls';
@@ -80,10 +79,8 @@
return `${baseDomain}${basePath}upload/${id}/${secret}`;
}
-async function mediaFromRow(row: Object): Promise<Media> {
- const dbType = await getDBType();
- const uploadExtra =
- dbType === 'mysql5.7' ? row.uploadExtra : JSON.parse(row.uploadExtra);
+function mediaFromRow(row: Object): Media {
+ const uploadExtra = JSON.parse(row.uploadExtra);
const { width, height, loop } = uploadExtra;
const { uploadType: type, uploadSecret: secret } = row;
@@ -112,7 +109,7 @@
WHERE id IN (${mediaIDs}) AND uploader = ${viewer.id} AND container IS NULL
`;
const [result] = await dbQuery(query);
- return await Promise.all(result.map(mediaFromRow));
+ return result.map(mediaFromRow);
}
export {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 11:37 PM (17 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2572823
Default Alt Text
D4834.diff (5 KB)
Attached To
Mode
D4834: [keyserver] Move mediaFromRow and rawMessageInfoFromRows back to not return a Promise
Attached
Detach File
Event Timeline
Log In to Comment