Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3374373
D4521.id14551.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
28 KB
Referenced Files
None
Subscribers
None
D4521.id14551.diff
View Options
diff --git a/keyserver/src/creators/message-creator.js b/keyserver/src/creators/message-creator.js
--- a/keyserver/src/creators/message-creator.js
+++ b/keyserver/src/creators/message-creator.js
@@ -26,6 +26,7 @@
appendSQLArray,
mergeOrConditions,
} from '../database/database';
+import { getDBType } from '../database/db-config';
import { fetchMessageInfoForLocalID } from '../fetchers/message-fetchers';
import { fetchOtherSessionsForViewer } from '../fetchers/session-fetchers';
import { fetchServerThreadInfos } from '../fetchers/thread-fetchers';
@@ -300,13 +301,15 @@
`);
const perUserInfo = new Map<string, UserThreadInfo>();
- const [result] = await dbQuery(query);
+ const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
for (const row of result) {
const userID = row.user.toString();
const threadID = row.thread.toString();
const deviceToken = row.device_token;
const focusedUser = !!row.focused_user;
- const { platform, versions } = row;
+ const { platform } = row;
+ const versions =
+ dbType === 'mysql5.7' ? row.versions : JSON.parse(row.versions);
let thisUserInfo = perUserInfo.get(userID);
if (!thisUserInfo) {
thisUserInfo = {
@@ -321,9 +324,14 @@
// it once
for (const subthread of subthreadPermissionsToCheck) {
const isSubthreadMember = row[`subthread${subthread}_role`] > 0;
- const permissions = row[`subthread${subthread}_permissions`];
+ const rawSubthreadPermissions =
+ row[`subthread${subthread}_permissions`];
+ const subthreadPermissions =
+ dbType === 'mysql5.7'
+ ? rawSubthreadPermissions
+ : JSON.parse(rawSubthreadPermissions);
const canSeeSubthread = permissionLookup(
- permissions,
+ subthreadPermissions,
threadPermissions.KNOW_OF,
);
if (!canSeeSubthread) {
@@ -334,7 +342,7 @@
// notification from the subthread
if (
!isSubthreadMember ||
- !permissionLookup(permissions, threadPermissions.VISIBLE)
+ !permissionLookup(subthreadPermissions, threadPermissions.VISIBLE)
) {
thisUserInfo.subthreadsCanNotify.add(subthread);
}
diff --git a/keyserver/src/fetchers/entry-fetchers.js b/keyserver/src/fetchers/entry-fetchers.js
--- a/keyserver/src/fetchers/entry-fetchers.js
+++ b/keyserver/src/fetchers/entry-fetchers.js
@@ -29,6 +29,7 @@
mergeAndConditions,
mergeOrConditions,
} from '../database/database';
+import { getDBType } from '../database/db-config';
import type { SQLStatementType } from '../database/types';
import type { Viewer } from '../session/viewer';
import { creationString } from '../utils/idempotent';
@@ -154,7 +155,7 @@
LEFT JOIN memberships m ON m.thread = t.id AND m.user = ${viewerID}
WHERE e.id = ${entryID}
`;
- const [result] = await dbQuery(query);
+ const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
if (result.length === 0) {
return false;
@@ -172,7 +173,9 @@
return false;
}
- return permissionLookup(row.permissions, permission);
+ const permissions =
+ dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions);
+ return permissionLookup(permissions, permission);
}
async function fetchEntryRevisionInfo(
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,6 +31,7 @@
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';
@@ -216,13 +217,22 @@
}
async function rawMessageInfoFromRows(
- rows: $ReadOnlyArray<Object>,
+ 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),
+ }));
+ }
+
const type = mostRecentRowType(rows);
const messageSpec = messageSpecs[type];
diff --git a/keyserver/src/fetchers/report-fetchers.js b/keyserver/src/fetchers/report-fetchers.js
--- a/keyserver/src/fetchers/report-fetchers.js
+++ b/keyserver/src/fetchers/report-fetchers.js
@@ -11,6 +11,7 @@
import { values } from 'lib/utils/objects';
import { dbQuery, SQL } from '../database/database';
+import { getDBType } from '../database/db-config';
import type { Viewer } from '../session/viewer';
async function fetchErrorReportInfos(
@@ -30,18 +31,19 @@
query.append(SQL`WHERE r.id < ${request.cursor} `);
}
query.append(SQL`ORDER BY r.id DESC`);
- const [result] = await dbQuery(query);
+ const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
const reports = [];
const userInfos = {};
for (const row of result) {
const viewerID = row.user.toString();
- let { platformDetails } = row.report;
+ const report = dbType === 'mysql5.7' ? row.report : JSON.parse(row.report);
+ let { platformDetails } = report;
if (!platformDetails) {
platformDetails = {
platform: row.platform,
- codeVersion: row.report.codeVersion,
- stateVersion: row.report.stateVersion,
+ codeVersion: report.codeVersion,
+ stateVersion: report.stateVersion,
};
}
reports.push({
@@ -74,22 +76,23 @@
FROM reports
WHERE id = ${id} AND type = ${reportTypes.ERROR}
`;
- const [result] = await dbQuery(query);
+ const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
if (result.length === 0) {
throw new ServerError('invalid_parameters');
}
const row = result[0];
- const _persist = row.report.preloadedState._persist
- ? row.report.preloadedState._persist
+ const report = dbType === 'mysql5.7' ? row.report : JSON.parse(row.report);
+ const _persist = report.preloadedState._persist
+ ? report.preloadedState._persist
: {};
const navState =
- row.report.currentState && row.report.currentState.navState
- ? row.report.currentState.navState
+ report.currentState && report.currentState.navState
+ ? report.currentState.navState
: undefined;
return {
preloadedState: {
- ...row.report.preloadedState,
+ ...report.preloadedState,
_persist: {
..._persist,
// Setting this to false disables redux-persist
@@ -98,7 +101,7 @@
navState,
frozen: true,
},
- payload: row.report.actions,
+ payload: report.actions,
};
}
diff --git a/keyserver/src/fetchers/role-fetchers.js b/keyserver/src/fetchers/role-fetchers.js
--- a/keyserver/src/fetchers/role-fetchers.js
+++ b/keyserver/src/fetchers/role-fetchers.js
@@ -3,6 +3,7 @@
import type { RoleInfo } from 'lib/types/thread-types';
import { dbQuery, SQL } from '../database/database';
+import { getDBType } from '../database/db-config';
async function fetchRoles(threadID: string): Promise<RoleInfo[]> {
const query = SQL`
@@ -11,14 +12,15 @@
LEFT JOIN threads t ON t.id = r.thread
WHERE r.thread = ${threadID}
`;
- const [result] = await dbQuery(query);
+ const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
const roles = [];
for (const row of result) {
roles.push({
id: row.id.toString(),
name: row.name,
- permissions: row.permissions,
+ permissions:
+ dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
isDefault: Boolean(row.is_default),
});
}
diff --git a/keyserver/src/fetchers/session-fetchers.js b/keyserver/src/fetchers/session-fetchers.js
--- a/keyserver/src/fetchers/session-fetchers.js
+++ b/keyserver/src/fetchers/session-fetchers.js
@@ -3,6 +3,7 @@
import type { CalendarQuery } from 'lib/types/entry-types';
import { dbQuery, SQL } from '../database/database';
+import { getDBType } from '../database/db-config';
import type { Viewer } from '../session/viewer';
type CalendarSessionResult = {
@@ -20,13 +21,13 @@
WHERE m.thread = ${threadID} AND m.role > 0
AND s.query IS NOT NULL
`;
- const [result] = await dbQuery(query);
+ const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
const filters = [];
for (const row of result) {
filters.push({
userID: row.user.toString(),
session: row.id.toString(),
- calendarQuery: row.query,
+ calendarQuery: dbType === 'mysql5.7' ? row.query : JSON.parse(row.query),
});
}
return filters;
diff --git a/keyserver/src/fetchers/thread-fetchers.js b/keyserver/src/fetchers/thread-fetchers.js
--- a/keyserver/src/fetchers/thread-fetchers.js
+++ b/keyserver/src/fetchers/thread-fetchers.js
@@ -16,6 +16,7 @@
import { ServerError } from 'lib/utils/errors';
import { dbQuery, SQL } from '../database/database';
+import { getDBType } from '../database/db-config';
import type { SQLStatementType } from '../database/types';
import type { Viewer } from '../session/viewer';
@@ -47,7 +48,7 @@
`
.append(whereClause)
.append(SQL` ORDER BY m.user ASC`);
- const [result] = await dbQuery(query);
+ const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
const threadInfos = {};
for (const row of result) {
@@ -82,18 +83,27 @@
threadInfos[threadID].roles[role] = {
id: role,
name: row.role_name,
- permissions: JSON.parse(row.role_permissions),
+ permissions:
+ dbType === 'mysql5.7'
+ ? row.role_permissions
+ : JSON.parse(row.role_permissions),
isDefault: role === row.default_role.toString(),
};
}
if (row.user) {
const userID = row.user.toString();
- const allPermissions = getAllThreadPermissions(row.permissions, threadID);
+ const allPermissions = getAllThreadPermissions(
+ dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
+ threadID,
+ );
threadInfos[threadID].members.push({
id: userID,
permissions: allPermissions,
role: row.role ? role : null,
- subscription: row.subscription,
+ subscription:
+ dbType === 'mysql5.7'
+ ? row.subscription
+ : JSON.parse(row.subscription),
unread: row.role ? !!row.unread : null,
isSender: !!row.sender,
});
diff --git a/keyserver/src/fetchers/thread-permission-fetchers.js b/keyserver/src/fetchers/thread-permission-fetchers.js
--- a/keyserver/src/fetchers/thread-permission-fetchers.js
+++ b/keyserver/src/fetchers/thread-permission-fetchers.js
@@ -19,6 +19,7 @@
} from 'lib/types/thread-types';
import { dbQuery, SQL } from '../database/database';
+import { getDBType } from '../database/db-config';
import type { Viewer } from '../session/viewer';
import { fetchThreadInfos } from './thread-fetchers';
import { fetchKnownUserInfos } from './user-fetchers';
@@ -38,13 +39,13 @@
FROM memberships
WHERE thread = ${threadID} AND user = ${viewerID}
`;
- const [result] = await dbQuery(query);
+ const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
if (result.length === 0) {
return null;
}
const row = result[0];
- return row.permissions;
+ return dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions);
}
function checkThreadPermission(
@@ -119,13 +120,19 @@
}
}
- const [[result], disabledThreadIDs] = await Promise.all([
+ const [[result], dbType, disabledThreadIDs] = await Promise.all([
dbQuery(query),
+ getDBType(),
checkThreadsFrozen(viewer, permissionsToCheck, threadIDs),
]);
return result
- .map(row => ({ ...row, threadID: row.threadID.toString() }))
+ .map(row => ({
+ ...row,
+ threadID: row.threadID.toString(),
+ permissions:
+ dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
+ }))
.filter(
row =>
isThreadValid(row.permissions, row.role, checks) &&
@@ -236,9 +243,13 @@
FROM memberships
WHERE thread = ${params.parentThreadID} AND user IN (${allCandidates})
`;
- const [result] = await dbQuery(parentPermissionsQuery);
+ const [[result], dbType] = await Promise.all([
+ dbQuery(parentPermissionsQuery),
+ getDBType(),
+ ]);
for (const row of result) {
- parentPermissions[row.user.toString()] = row.permissions;
+ parentPermissions[row.user.toString()] =
+ dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions);
}
return parentPermissions;
})();
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,6 +4,7 @@
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,8 +81,12 @@
}
async function mediaFromRow(row: Object): Promise<Media> {
+ const dbType = await getDBType();
+ const uploadExtra =
+ dbType === 'mysql5.7' ? row.uploadExtra : JSON.parse(row.uploadExtra);
+ const { width, height, loop } = uploadExtra;
+
const { uploadType: type, uploadSecret: secret } = row;
- const { width, height, loop } = row.uploadExtra;
const id = row.uploadID.toString();
const dimensions = { width, height };
const uri = getUploadURL(id, secret);
diff --git a/keyserver/src/push/rescind.js b/keyserver/src/push/rescind.js
--- a/keyserver/src/push/rescind.js
+++ b/keyserver/src/push/rescind.js
@@ -9,6 +9,7 @@
import createIDs from '../creators/id-creator';
import { dbQuery, SQL } from '../database/database';
+import { getDBType } from '../database/db-config';
import type { SQLStatementType } from '../database/types';
import { getAPNsNotificationTopic } from './providers';
import { apnPush, fcmPush } from './utils';
@@ -36,16 +37,19 @@
`);
fetchQuery.append(notifCondition);
fetchQuery.append(SQL` GROUP BY n.id, m.user`);
- const [fetchResult] = await dbQuery(fetchQuery);
+ const [[fetchResult], dbType] = await Promise.all([
+ dbQuery(fetchQuery),
+ getDBType(),
+ ]);
const deliveryPromises = {};
const notifInfo = {};
const rescindedIDs = [];
const receivingDeviceTokens = [];
for (const row of fetchResult) {
- const deliveries = Array.isArray(row.delivery)
- ? row.delivery
- : [row.delivery];
+ const rawDelivery =
+ dbType === 'mysql5.7' ? row.delivery : JSON.parse(row.delivery);
+ const deliveries = Array.isArray(rawDelivery) ? rawDelivery : [rawDelivery];
const id = row.id.toString();
const threadID = row.thread.toString();
notifInfo[id] = {
diff --git a/keyserver/src/push/send.js b/keyserver/src/push/send.js
--- a/keyserver/src/push/send.js
+++ b/keyserver/src/push/send.js
@@ -33,6 +33,7 @@
import createIDs from '../creators/id-creator';
import { createUpdates } from '../creators/update-creator';
import { dbQuery, SQL, mergeOrConditions } from '../database/database';
+import { getDBType } from '../database/db-config';
import type { CollapsableNotifInfo } from '../fetchers/message-fetchers';
import { fetchCollapsableNotifs } from '../fetchers/message-fetchers';
import { fetchServerThreadInfos } from '../fetchers/thread-fetchers';
@@ -752,17 +753,26 @@
SQL`AND device_token NOT IN (${excludeDeviceTokens}) `,
);
}
- const [unreadCounts, [deviceTokenResult], [dbID]] = await Promise.all([
+ const [
+ unreadCounts,
+ [deviceTokenResult],
+ [dbID],
+ dbType,
+ ] = await Promise.all([
getUnreadCounts([userID]),
dbQuery(deviceTokenQuery),
createIDs('notifications', 1),
+ getDBType(),
]);
const unreadCount = unreadCounts[userID];
const devices = deviceTokenResult.map(row => ({
deviceType: row.platform,
deviceToken: row.device_token,
- codeVersion: row.versions?.codeVersion,
+ codeVersion:
+ dbType === 'mysql5.7'
+ ? row.versions?.codeVersion
+ : JSON.parse(row.versions)?.codeVersion,
}));
const byDeviceType = getDevicesByDeviceType(devices);
diff --git a/keyserver/src/session/cookies.js b/keyserver/src/session/cookies.js
--- a/keyserver/src/session/cookies.js
+++ b/keyserver/src/session/cookies.js
@@ -27,6 +27,7 @@
import createIDs from '../creators/id-creator';
import { createSession } from '../creators/session-creator';
import { dbQuery, SQL } from '../database/database';
+import { getDBType } from '../database/db-config';
import { deleteCookie } from '../deleters/cookie-deleters';
import { handleAsyncPromise } from '../responders/handlers';
import { clearDeviceToken } from '../updaters/device-token-updaters';
@@ -89,8 +90,9 @@
FROM cookies
WHERE id = ${cookieID} AND user IS NOT NULL
`;
- const [[result], allSessionInfo] = await Promise.all([
+ const [[result], dbType, allSessionInfo] = await Promise.all([
dbQuery(query),
+ getDBType(),
fetchSessionInfo(sessionParameterInfo, cookieID),
]);
if (result.length === 0) {
@@ -111,10 +113,14 @@
const cookieRow = result[0];
let platformDetails = null;
if (cookieRow.versions) {
+ const versions =
+ dbType === 'mysql5.7'
+ ? cookieRow.versions
+ : JSON.parse(cookieRow.versions);
platformDetails = {
platform: cookieRow.platform,
- codeVersion: cookieRow.versions.codeVersion,
- stateVersion: cookieRow.versions.stateVersion,
+ codeVersion: versions.codeVersion,
+ stateVersion: versions.stateVersion,
};
} else {
platformDetails = { platform: cookieRow.platform };
@@ -176,8 +182,9 @@
FROM cookies
WHERE id = ${cookieID} AND user IS NULL
`;
- const [[result], allSessionInfo] = await Promise.all([
+ const [[result], dbType, allSessionInfo] = await Promise.all([
dbQuery(query),
+ getDBType(),
fetchSessionInfo(sessionParameterInfo, cookieID),
]);
if (result.length === 0) {
@@ -198,10 +205,14 @@
const cookieRow = result[0];
let platformDetails = null;
if (cookieRow.platform && cookieRow.versions) {
+ const versions =
+ dbType === 'mysql5.7'
+ ? cookieRow.versions
+ : JSON.parse(cookieRow.versions);
platformDetails = {
platform: cookieRow.platform,
- codeVersion: cookieRow.versions.codeVersion,
- stateVersion: cookieRow.versions.stateVersion,
+ codeVersion: versions.codeVersion,
+ stateVersion: versions.stateVersion,
};
} else if (cookieRow.platform) {
platformDetails = { platform: cookieRow.platform };
@@ -261,7 +272,7 @@
FROM sessions
WHERE id = ${session} AND cookie = ${cookieID}
`;
- const [result] = await dbQuery(query);
+ const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
if (result.length === 0) {
return null;
}
@@ -269,7 +280,8 @@
sessionID,
lastValidated: result[0].last_validated,
lastUpdate: result[0].last_update,
- calendarQuery: result[0].query,
+ calendarQuery:
+ dbType === 'mysql5.7' ? result[0].query : JSON.parse(result[0].query),
};
}
diff --git a/keyserver/src/updaters/thread-permission-updaters.js b/keyserver/src/updaters/thread-permission-updaters.js
--- a/keyserver/src/updaters/thread-permission-updaters.js
+++ b/keyserver/src/updaters/thread-permission-updaters.js
@@ -30,6 +30,7 @@
type UpdatesForCurrentSession,
} from '../creators/update-creator';
import { dbQuery, SQL } from '../database/database';
+import { getDBType } from '../database/db-config';
import {
fetchServerThreadInfos,
rawThreadInfosFromServerThreadInfos,
@@ -116,11 +117,13 @@
WHERE t.id = ${threadID} AND cm.user IN (${userIDs})
`;
const [
+ dbType,
[membershipResults],
[parentMembershipResults],
containingMembershipResults,
roleThreadResult,
] = await Promise.all([
+ getDBType(),
dbQuery(membershipQuery),
dbQuery(parentMembershipQuery),
(async () => {
@@ -148,8 +151,12 @@
const userID = row.user.toString();
existingMembershipInfo.set(userID, {
oldRole: row.role.toString(),
- oldPermissions: row.permissions,
- oldPermissionsForChildren: row.permissions_for_children,
+ oldPermissions:
+ dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
+ oldPermissionsForChildren:
+ dbType === 'mysql5.7'
+ ? row.permissions_for_children
+ : JSON.parse(row.permissions_for_children),
});
}
@@ -160,7 +167,10 @@
continue;
}
ancestorMembershipInfo.set(userID, {
- permissionsFromParent: row.permissions_from_parent,
+ permissionsFromParent:
+ dbType === 'mysql5.7'
+ ? row.permissions_from_parent
+ : JSON.parse(row.permissions_from_parent),
});
}
for (const row of containingMembershipResults) {
@@ -352,7 +362,7 @@
INNER JOIN roles r ON r.thread = t.id AND r.id = ${role}
WHERE t.id = ${threadID}
`;
- const [result] = await dbQuery(query);
+ const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
if (result.length === 0) {
throw new ServerError('internal_error');
}
@@ -365,7 +375,8 @@
? row.parent_thread_id.toString()
: null,
hasContainingThreadID: row.containing_thread_id !== null,
- rolePermissions: row.permissions,
+ rolePermissions:
+ dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
};
} else {
const query = SQL`
@@ -375,7 +386,7 @@
INNER JOIN roles r ON r.thread = t.id AND r.id = t.default_role
WHERE t.id = ${threadID}
`;
- const [result] = await dbQuery(query);
+ const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
if (result.length === 0) {
throw new ServerError('internal_error');
}
@@ -388,7 +399,8 @@
? row.parent_thread_id.toString()
: null,
hasContainingThreadID: row.containing_thread_id !== null,
- rolePermissions: row.permissions,
+ rolePermissions:
+ dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
};
}
}
@@ -573,27 +585,30 @@
const threadIDs = ancestors.map(ancestor => ancestor.threadID);
const rows = [];
- while (threadIDs.length > 0) {
- const batch = threadIDs.splice(0, fetchDescendantsBatchSize);
- const query = SQL`
- SELECT t.id, m.user, t.type, t.depth, t.parent_thread_id,
- t.containing_thread_id, r.permissions AS role_permissions, m.permissions,
- m.permissions_for_children, m.role,
- pm.permissions_for_children AS permissions_from_parent,
- cm.role AS containing_role
- FROM threads t
- INNER JOIN memberships m ON m.thread = t.id
- LEFT JOIN memberships pm
- ON pm.thread = t.parent_thread_id AND pm.user = m.user
- LEFT JOIN memberships cm
- ON cm.thread = t.containing_thread_id AND cm.user = m.user
- LEFT JOIN roles r ON r.id = m.role
- WHERE t.parent_thread_id IN (${batch})
- OR t.containing_thread_id IN (${batch})
- `;
- const [results] = await dbQuery(query);
- pushAll(rows, results);
- }
+ const queriesPromise = (async () => {
+ while (threadIDs.length > 0) {
+ const batch = threadIDs.splice(0, fetchDescendantsBatchSize);
+ const query = SQL`
+ SELECT t.id, m.user, t.type, t.depth, t.parent_thread_id,
+ t.containing_thread_id, r.permissions AS role_permissions, m.permissions,
+ m.permissions_for_children, m.role,
+ pm.permissions_for_children AS permissions_from_parent,
+ cm.role AS containing_role
+ FROM threads t
+ INNER JOIN memberships m ON m.thread = t.id
+ LEFT JOIN memberships pm
+ ON pm.thread = t.parent_thread_id AND pm.user = m.user
+ LEFT JOIN memberships cm
+ ON cm.thread = t.containing_thread_id AND cm.user = m.user
+ LEFT JOIN roles r ON r.id = m.role
+ WHERE t.parent_thread_id IN (${batch})
+ OR t.containing_thread_id IN (${batch})
+ `;
+ const [results] = await dbQuery(query);
+ pushAll(rows, results);
+ }
+ })();
+ const [dbType] = await Promise.all([getDBType(), queriesPromise]);
const descendantThreadInfos: Map<string, DescendantInfo> = new Map();
for (const row of rows) {
@@ -616,10 +631,20 @@
const userID = row.user.toString();
descendantThreadInfo.users.set(userID, {
curRole: row.role.toString(),
- curRolePermissions: row.role_permissions,
- curPermissions: row.permissions,
- curPermissionsForChildren: row.permissions_for_children,
- curPermissionsFromParent: row.permissions_from_parent,
+ curRolePermissions:
+ dbType === 'mysql5.7'
+ ? row.role_permissions
+ : JSON.parse(row.role_permissions),
+ curPermissions:
+ dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
+ curPermissionsForChildren:
+ dbType === 'mysql5.7'
+ ? row.permissions_for_children
+ : JSON.parse(row.permissions_for_children),
+ curPermissionsFromParent:
+ dbType === 'mysql5.7'
+ ? row.permissions_from_parent
+ : JSON.parse(row.permissions_from_parent),
curMemberOfContainingThread: row.containing_role > 0,
});
}
@@ -724,10 +749,12 @@
WHERE t.id = ${threadID}
`;
const [
+ dbType,
[threadResults],
[membershipResults],
[parentMembershipResults],
] = await Promise.all([
+ getDBType(),
dbQuery(threadQuery),
dbQuery(membershipQuery),
dbQuery(parentMembershipQuery),
@@ -750,9 +777,16 @@
const userID = row.user.toString();
membershipInfo.set(userID, {
role: row.role.toString(),
- permissions: row.permissions,
- permissionsForChildren: row.permissions_for_children,
- rolePermissions: row.role_permissions,
+ permissions:
+ dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
+ permissionsForChildren:
+ dbType === 'mysql5.7'
+ ? row.permissions_for_children
+ : JSON.parse(row.permissions_for_children),
+ rolePermissions:
+ dbType === 'mysql5.7'
+ ? row.role_permissions
+ : JSON.parse(row.role_permissions),
memberOfContainingThread: !!(
row.containing_role && row.containing_role > 0
),
@@ -760,12 +794,16 @@
}
for (const row of parentMembershipResults) {
const userID = row.user.toString();
+ const permissionsFromParent =
+ dbType === 'mysql5.7'
+ ? row.permissions_from_parent
+ : JSON.parse(row.permissions_from_parent);
const membership = membershipInfo.get(userID);
if (membership) {
- membership.permissionsFromParent = row.permissions_from_parent;
+ membership.permissionsFromParent = permissionsFromParent;
} else {
membershipInfo.set(userID, {
- permissionsFromParent: row.permissions_from_parent,
+ permissionsFromParent: permissionsFromParent,
});
}
}
diff --git a/keyserver/src/updaters/thread-updaters.js b/keyserver/src/updaters/thread-updaters.js
--- a/keyserver/src/updaters/thread-updaters.js
+++ b/keyserver/src/updaters/thread-updaters.js
@@ -31,6 +31,7 @@
import { getRolePermissionBlobs } from '../creators/role-creator';
import { createUpdates } from '../creators/update-creator';
import { dbQuery, SQL } from '../database/database';
+import { getDBType } from '../database/db-config';
import { fetchEntryInfos } from '../fetchers/entry-fetchers';
import { fetchMessageInfos } from '../fetchers/message-fetchers';
import {
@@ -531,9 +532,15 @@
LEFT JOIN roles r ON r.id = t.default_role
WHERE t.id = ${request.threadID}
`;
- const [result] = await dbQuery(rolePermissionsQuery);
+ const [[result], dbType] = await Promise.all([
+ dbQuery(rolePermissionsQuery),
+ getDBType(),
+ ]);
if (result.length > 0) {
- rolePermissions = result[0].permissions;
+ rolePermissions =
+ dbType === 'mysql5.7'
+ ? result[0].permissions
+ : JSON.parse(result[0].permissions);
}
}
if (!rolePermissions) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 3:19 PM (20 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2590280
Default Alt Text
D4521.id14551.diff (28 KB)
Attached To
Mode
D4521: [keyserver] Parse JSON columns returned from MariaDB
Attached
Detach File
Event Timeline
Log In to Comment