Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3375219
D4835.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
32 KB
Referenced Files
None
Subscribers
None
D4835.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,7 +26,6 @@
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';
@@ -301,15 +300,14 @@
`);
const perUserInfo = new Map<string, UserThreadInfo>();
- const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
+ const [result] = await dbQuery(query);
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 } = row;
- const versions =
- dbType === 'mysql5.7' ? row.versions : JSON.parse(row.versions);
+ const versions = JSON.parse(row.versions);
let thisUserInfo = perUserInfo.get(userID);
if (!thisUserInfo) {
thisUserInfo = {
@@ -326,10 +324,7 @@
const isSubthreadMember = row[`subthread${subthread}_role`] > 0;
const rawSubthreadPermissions =
row[`subthread${subthread}_permissions`];
- const subthreadPermissions =
- dbType === 'mysql5.7'
- ? rawSubthreadPermissions
- : JSON.parse(rawSubthreadPermissions);
+ const subthreadPermissions = JSON.parse(rawSubthreadPermissions);
const canSeeSubthread = permissionLookup(
subthreadPermissions,
threadPermissions.KNOW_OF,
diff --git a/keyserver/src/creators/session-creator.js b/keyserver/src/creators/session-creator.js
--- a/keyserver/src/creators/session-creator.js
+++ b/keyserver/src/creators/session-creator.js
@@ -3,7 +3,6 @@
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';
async function createSession(
@@ -25,23 +24,11 @@
INSERT INTO sessions (id, user, cookie, query,
creation_time, last_update, last_validated)
VALUES ${[row]}
- `;
- const dbType = await getDBType();
- if (dbType === 'mysql5.7') {
- query.append(SQL`
- ON DUPLICATE KEY UPDATE
- query = VALUES(query),
- last_update = VALUES(last_update),
- last_validated = VALUES(last_validated)
- `);
- } else {
- query.append(SQL`
ON DUPLICATE KEY UPDATE
query = VALUE(query),
last_update = VALUE(last_update),
last_validated = VALUE(last_validated)
- `);
- }
+ `;
await dbQuery(query);
viewer.setSessionInfo({
lastValidated: time,
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,7 +29,6 @@
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';
@@ -155,7 +154,7 @@
LEFT JOIN memberships m ON m.thread = t.id AND m.user = ${viewerID}
WHERE e.id = ${entryID}
`;
- const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
+ const [result] = await dbQuery(query);
if (result.length === 0) {
return false;
@@ -173,8 +172,7 @@
return false;
}
- const permissions =
- dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions);
+ const permissions = JSON.parse(row.permissions);
return permissionLookup(permissions, permission);
}
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,7 +11,6 @@
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(
@@ -31,13 +30,13 @@
query.append(SQL`WHERE r.id < ${request.cursor} `);
}
query.append(SQL`ORDER BY r.id DESC`);
- const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
+ const [result] = await dbQuery(query);
const reports = [];
const userInfos = {};
for (const row of result) {
const viewerID = row.user.toString();
- const report = dbType === 'mysql5.7' ? row.report : JSON.parse(row.report);
+ const report = JSON.parse(row.report);
let { platformDetails } = report;
if (!platformDetails) {
platformDetails = {
@@ -76,13 +75,13 @@
FROM reports
WHERE id = ${id} AND type = ${reportTypes.ERROR}
`;
- const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
+ const [result] = await dbQuery(query);
if (result.length === 0) {
throw new ServerError('invalid_parameters');
}
const row = result[0];
- const report = dbType === 'mysql5.7' ? row.report : JSON.parse(row.report);
+ const report = JSON.parse(row.report);
const _persist = report.preloadedState._persist
? report.preloadedState._persist
: {};
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,7 +3,6 @@
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`
@@ -12,15 +11,14 @@
LEFT JOIN threads t ON t.id = r.thread
WHERE r.thread = ${threadID}
`;
- const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
+ const [result] = await dbQuery(query);
const roles = [];
for (const row of result) {
roles.push({
id: row.id.toString(),
name: row.name,
- permissions:
- dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
+ 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,7 +3,6 @@
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 = {
@@ -21,13 +20,13 @@
WHERE m.thread = ${threadID} AND m.role > 0
AND s.query IS NOT NULL
`;
- const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
+ const [result] = await dbQuery(query);
const filters = [];
for (const row of result) {
filters.push({
userID: row.user.toString(),
session: row.id.toString(),
- calendarQuery: dbType === 'mysql5.7' ? row.query : JSON.parse(row.query),
+ calendarQuery: 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,7 +16,6 @@
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';
@@ -48,7 +47,7 @@
`
.append(whereClause)
.append(SQL` ORDER BY m.user ASC`);
- const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
+ const [result] = await dbQuery(query);
const threadInfos = {};
for (const row of result) {
@@ -83,27 +82,21 @@
threadInfos[threadID].roles[role] = {
id: role,
name: row.role_name,
- permissions:
- dbType === 'mysql5.7'
- ? row.role_permissions
- : JSON.parse(row.role_permissions),
+ permissions: JSON.parse(row.role_permissions),
isDefault: role === row.default_role.toString(),
};
}
if (row.user) {
const userID = row.user.toString();
const allPermissions = getAllThreadPermissions(
- dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
+ JSON.parse(row.permissions),
threadID,
);
threadInfos[threadID].members.push({
id: userID,
permissions: allPermissions,
role: row.role ? role : null,
- subscription:
- dbType === 'mysql5.7'
- ? row.subscription
- : JSON.parse(row.subscription),
+ 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,7 +19,6 @@
} 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';
@@ -39,13 +38,13 @@
FROM memberships
WHERE thread = ${threadID} AND user = ${viewerID}
`;
- const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
+ const [result] = await dbQuery(query);
if (result.length === 0) {
return null;
}
const row = result[0];
- return dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions);
+ return JSON.parse(row.permissions);
}
function checkThreadPermission(
@@ -120,9 +119,8 @@
}
}
- const [[result], dbType, disabledThreadIDs] = await Promise.all([
+ const [[result], disabledThreadIDs] = await Promise.all([
dbQuery(query),
- getDBType(),
checkThreadsFrozen(viewer, permissionsToCheck, threadIDs),
]);
@@ -130,8 +128,7 @@
.map(row => ({
...row,
threadID: row.threadID.toString(),
- permissions:
- dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
+ permissions: JSON.parse(row.permissions),
}))
.filter(
row =>
@@ -243,13 +240,9 @@
FROM memberships
WHERE thread = ${params.parentThreadID} AND user IN (${allCandidates})
`;
- const [[result], dbType] = await Promise.all([
- dbQuery(parentPermissionsQuery),
- getDBType(),
- ]);
+ const [result] = await dbQuery(parentPermissionsQuery);
for (const row of result) {
- parentPermissions[row.user.toString()] =
- dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions);
+ parentPermissions[row.user.toString()] = JSON.parse(row.permissions);
}
return parentPermissions;
})();
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,7 +9,6 @@
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';
@@ -37,18 +36,14 @@
`);
fetchQuery.append(notifCondition);
fetchQuery.append(SQL` GROUP BY n.id, m.user`);
- const [[fetchResult], dbType] = await Promise.all([
- dbQuery(fetchQuery),
- getDBType(),
- ]);
+ const [fetchResult] = await dbQuery(fetchQuery);
const deliveryPromises = {};
const notifInfo = {};
const rescindedIDs = [];
const receivingDeviceTokens = [];
for (const row of fetchResult) {
- const rawDelivery =
- dbType === 'mysql5.7' ? row.delivery : JSON.parse(row.delivery);
+ const rawDelivery = JSON.parse(row.delivery);
const deliveries = Array.isArray(rawDelivery) ? rawDelivery : [rawDelivery];
const id = row.id.toString();
const threadID = row.thread.toString();
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
@@ -34,7 +34,6 @@
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';
@@ -770,26 +769,17 @@
SQL`AND device_token NOT IN (${excludeDeviceTokens}) `,
);
}
- const [
- unreadCounts,
- [deviceTokenResult],
- [dbID],
- dbType,
- ] = await Promise.all([
+ const [unreadCounts, [deviceTokenResult], [dbID]] = 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:
- dbType === 'mysql5.7'
- ? row.versions?.codeVersion
- : JSON.parse(row.versions)?.codeVersion,
+ 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,7 +27,6 @@
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';
@@ -90,9 +89,8 @@
FROM cookies
WHERE id = ${cookieID} AND user IS NOT NULL
`;
- const [[result], dbType, allSessionInfo] = await Promise.all([
+ const [[result], allSessionInfo] = await Promise.all([
dbQuery(query),
- getDBType(),
fetchSessionInfo(sessionParameterInfo, cookieID),
]);
if (result.length === 0) {
@@ -113,10 +111,7 @@
const cookieRow = result[0];
let platformDetails = null;
if (cookieRow.versions) {
- const versions =
- dbType === 'mysql5.7'
- ? cookieRow.versions
- : JSON.parse(cookieRow.versions);
+ const versions = JSON.parse(cookieRow.versions);
platformDetails = {
platform: cookieRow.platform,
codeVersion: versions.codeVersion,
@@ -182,9 +177,8 @@
FROM cookies
WHERE id = ${cookieID} AND user IS NULL
`;
- const [[result], dbType, allSessionInfo] = await Promise.all([
+ const [[result], allSessionInfo] = await Promise.all([
dbQuery(query),
- getDBType(),
fetchSessionInfo(sessionParameterInfo, cookieID),
]);
if (result.length === 0) {
@@ -205,10 +199,7 @@
const cookieRow = result[0];
let platformDetails = null;
if (cookieRow.platform && cookieRow.versions) {
- const versions =
- dbType === 'mysql5.7'
- ? cookieRow.versions
- : JSON.parse(cookieRow.versions);
+ const versions = JSON.parse(cookieRow.versions);
platformDetails = {
platform: cookieRow.platform,
codeVersion: versions.codeVersion,
@@ -272,7 +263,7 @@
FROM sessions
WHERE id = ${session} AND cookie = ${cookieID}
`;
- const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
+ const [result] = await dbQuery(query);
if (result.length === 0) {
return null;
}
@@ -280,8 +271,7 @@
sessionID,
lastValidated: result[0].last_validated,
lastUpdate: result[0].last_update,
- calendarQuery:
- dbType === 'mysql5.7' ? result[0].query : JSON.parse(result[0].query),
+ calendarQuery: JSON.parse(result[0].query),
};
}
diff --git a/keyserver/src/updaters/account-updaters.js b/keyserver/src/updaters/account-updaters.js
--- a/keyserver/src/updaters/account-updaters.js
+++ b/keyserver/src/updaters/account-updaters.js
@@ -14,7 +14,6 @@
import { createUpdates } from '../creators/update-creator';
import { dbQuery, SQL } from '../database/database';
-import { getDBType } from '../database/db-config';
import type { Viewer } from '../session/viewer';
async function accountUpdater(
@@ -98,18 +97,8 @@
const createOrUpdateSettingsQuery = SQL`
INSERT INTO settings (user, name, data)
VALUES ${[[viewer.id, request.name, request.data]]}
- `;
- const dbType = await getDBType();
- if (dbType === 'mysql5.7') {
- createOrUpdateSettingsQuery.append(SQL`
- ON DUPLICATE KEY UPDATE data = VALUES(data)
- `);
- } else {
- createOrUpdateSettingsQuery.append(SQL`
ON DUPLICATE KEY UPDATE data = VALUE(data)
- `);
- }
-
+ `;
await dbQuery(createOrUpdateSettingsQuery);
}
diff --git a/keyserver/src/updaters/activity-updaters.js b/keyserver/src/updaters/activity-updaters.js
--- a/keyserver/src/updaters/activity-updaters.js
+++ b/keyserver/src/updaters/activity-updaters.js
@@ -18,7 +18,6 @@
import { createUpdates } from '../creators/update-creator';
import { dbQuery, SQL, mergeOrConditions } from '../database/database';
-import { getDBType } from '../database/db-config';
import type { SQLStatementType } from '../database/types';
import { deleteActivityForViewerSession } from '../deleters/activity-deleters';
import {
@@ -272,17 +271,8 @@
const query = SQL`
INSERT INTO focused (user, session, thread, time)
VALUES ${focusedInsertRows}
- `;
- const dbType = await getDBType();
- if (dbType === 'mysql5.7') {
- query.append(SQL`
- ON DUPLICATE KEY UPDATE time = VALUES(time)
- `);
- } else {
- query.append(SQL`
ON DUPLICATE KEY UPDATE time = VALUE(time)
- `);
- }
+ `;
await dbQuery(query);
}
diff --git a/keyserver/src/updaters/relationship-updaters.js b/keyserver/src/updaters/relationship-updaters.js
--- a/keyserver/src/updaters/relationship-updaters.js
+++ b/keyserver/src/updaters/relationship-updaters.js
@@ -22,7 +22,6 @@
import { createThread } from '../creators/thread-creator';
import { createUpdates } from '../creators/update-creator';
import { dbQuery, SQL, mergeOrConditions } from '../database/database';
-import { getDBType } from '../database/db-config';
import { fetchFriendRequestRelationshipOperations } from '../fetchers/relationship-fetchers';
import { fetchUserInfos } from '../fetchers/user-fetchers';
import type { Viewer } from '../session/viewer';
@@ -38,10 +37,7 @@
}
const uniqueUserIDs = [...new Set(request.userIDs)];
- const [users, dbType] = await Promise.all([
- fetchUserInfos(uniqueUserIDs),
- getDBType(),
- ]);
+ const users = await fetchUserInfos(uniqueUserIDs);
let errors = {};
const userIDs: string[] = [];
@@ -125,16 +121,8 @@
const directedInsertQuery = SQL`
INSERT INTO relationships_directed (user1, user2, status)
VALUES ${directedInsertRows}
- `;
- if (dbType === 'mysql5.7') {
- directedInsertQuery.append(SQL`
- ON DUPLICATE KEY UPDATE status = VALUES(status)
- `);
- } else {
- directedInsertQuery.append(SQL`
ON DUPLICATE KEY UPDATE status = VALUE(status)
- `);
- }
+ `;
promises.push(dbQuery(directedInsertQuery));
}
if (directedDeleteIDs.length) {
@@ -186,16 +174,8 @@
const directedInsertQuery = SQL`
INSERT INTO relationships_directed (user1, user2, status)
VALUES ${directedRows}
- `;
- if (dbType === 'mysql5.7') {
- directedInsertQuery.append(SQL`
- ON DUPLICATE KEY UPDATE status = VALUES(status)
- `);
- } else {
- directedInsertQuery.append(SQL`
ON DUPLICATE KEY UPDATE status = VALUE(status)
- `);
- }
+ `;
const directedDeleteQuery = SQL`
DELETE FROM relationships_directed
WHERE status = ${directedStatus.PENDING_FRIEND} AND
@@ -262,24 +242,12 @@
INSERT INTO relationships_undirected (user1, user2, status)
VALUES ${rows}
`;
-
- const dbType = await getDBType();
if (greatest) {
- if (dbType === 'mysql5.7') {
- query.append(
- SQL`ON DUPLICATE KEY UPDATE status = GREATEST(status, VALUES(status))`,
- );
- } else {
- query.append(
- SQL`ON DUPLICATE KEY UPDATE status = GREATEST(status, VALUE(status))`,
- );
- }
+ query.append(
+ SQL`ON DUPLICATE KEY UPDATE status = GREATEST(status, VALUE(status))`,
+ );
} else {
- if (dbType === 'mysql5.7') {
- query.append(SQL`ON DUPLICATE KEY UPDATE status = VALUES(status)`);
- } else {
- query.append(SQL`ON DUPLICATE KEY UPDATE status = VALUE(status)`);
- }
+ query.append(SQL`ON DUPLICATE KEY UPDATE status = VALUE(status)`);
}
await dbQuery(query);
}
@@ -310,10 +278,7 @@
}
selectQuery.append(mergeOrConditions(conditions));
- const [[result], dbType] = await Promise.all([
- dbQuery(selectQuery),
- getDBType(),
- ]);
+ const [result] = await dbQuery(selectQuery);
const existingStatuses = new Map();
for (const row of result) {
existingStatuses.set(`${row.user1}|${row.user2}`, row.status);
@@ -332,16 +297,8 @@
const insertQuery = SQL`
INSERT INTO relationships_undirected (user1, user2, status)
VALUES ${insertRows}
- `;
- if (dbType === 'mysql5.7') {
- insertQuery.append(SQL`
- ON DUPLICATE KEY UPDATE status = GREATEST(status, VALUES(status))
- `);
- } else {
- insertQuery.append(SQL`
ON DUPLICATE KEY UPDATE status = GREATEST(status, VALUE(status))
- `);
- }
+ `;
await dbQuery(insertQuery);
return updateDatasForUserPairs(
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,7 +30,6 @@
type UpdatesForCurrentSession,
} from '../creators/update-creator';
import { dbQuery, SQL } from '../database/database';
-import { getDBType } from '../database/db-config';
import {
fetchServerThreadInfos,
rawThreadInfosFromServerThreadInfos,
@@ -117,13 +116,11 @@
WHERE t.id = ${threadID} AND cm.user IN (${userIDs})
`;
const [
- dbType,
[membershipResults],
[parentMembershipResults],
containingMembershipResults,
roleThreadResult,
] = await Promise.all([
- getDBType(),
dbQuery(membershipQuery),
dbQuery(parentMembershipQuery),
(async () => {
@@ -151,12 +148,8 @@
const userID = row.user.toString();
existingMembershipInfo.set(userID, {
oldRole: row.role.toString(),
- oldPermissions:
- dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
- oldPermissionsForChildren:
- dbType === 'mysql5.7'
- ? row.permissions_for_children
- : JSON.parse(row.permissions_for_children),
+ oldPermissions: JSON.parse(row.permissions),
+ oldPermissionsForChildren: JSON.parse(row.permissions_for_children),
});
}
@@ -167,10 +160,7 @@
continue;
}
ancestorMembershipInfo.set(userID, {
- permissionsFromParent:
- dbType === 'mysql5.7'
- ? row.permissions_from_parent
- : JSON.parse(row.permissions_from_parent),
+ permissionsFromParent: JSON.parse(row.permissions_from_parent),
});
}
for (const row of containingMembershipResults) {
@@ -362,7 +352,7 @@
INNER JOIN roles r ON r.thread = t.id AND r.id = ${role}
WHERE t.id = ${threadID}
`;
- const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
+ const [result] = await dbQuery(query);
if (result.length === 0) {
throw new ServerError('internal_error');
}
@@ -375,8 +365,7 @@
? row.parent_thread_id.toString()
: null,
hasContainingThreadID: row.containing_thread_id !== null,
- rolePermissions:
- dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
+ rolePermissions: JSON.parse(row.permissions),
};
} else {
const query = SQL`
@@ -386,7 +375,7 @@
INNER JOIN roles r ON r.thread = t.id AND r.id = t.default_role
WHERE t.id = ${threadID}
`;
- const [[result], dbType] = await Promise.all([dbQuery(query), getDBType()]);
+ const [result] = await dbQuery(query);
if (result.length === 0) {
throw new ServerError('internal_error');
}
@@ -399,8 +388,7 @@
? row.parent_thread_id.toString()
: null,
hasContainingThreadID: row.containing_thread_id !== null,
- rolePermissions:
- dbType === 'mysql5.7' ? row.permissions : JSON.parse(row.permissions),
+ rolePermissions: JSON.parse(row.permissions),
};
}
}
@@ -585,30 +573,27 @@
const threadIDs = ancestors.map(ancestor => ancestor.threadID);
const rows = [];
- 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]);
+ 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 descendantThreadInfos: Map<string, DescendantInfo> = new Map();
for (const row of rows) {
@@ -631,20 +616,10 @@
const userID = row.user.toString();
descendantThreadInfo.users.set(userID, {
curRole: row.role.toString(),
- 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),
+ curRolePermissions: JSON.parse(row.role_permissions),
+ curPermissions: JSON.parse(row.permissions),
+ curPermissionsForChildren: JSON.parse(row.permissions_for_children),
+ curPermissionsFromParent: JSON.parse(row.permissions_from_parent),
curMemberOfContainingThread: row.containing_role > 0,
});
}
@@ -749,12 +724,10 @@
WHERE t.id = ${threadID}
`;
const [
- dbType,
[threadResults],
[membershipResults],
[parentMembershipResults],
] = await Promise.all([
- getDBType(),
dbQuery(threadQuery),
dbQuery(membershipQuery),
dbQuery(parentMembershipQuery),
@@ -777,16 +750,9 @@
const userID = row.user.toString();
membershipInfo.set(userID, {
role: row.role.toString(),
- 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),
+ permissions: JSON.parse(row.permissions),
+ permissionsForChildren: JSON.parse(row.permissions_for_children),
+ rolePermissions: JSON.parse(row.role_permissions),
memberOfContainingThread: !!(
row.containing_role && row.containing_role > 0
),
@@ -794,10 +760,7 @@
}
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 permissionsFromParent = JSON.parse(row.permissions_from_parent);
const membership = membershipInfo.get(userID);
if (membership) {
membership.permissionsFromParent = permissionsFromParent;
@@ -955,29 +918,12 @@
// column and this is an INSERT, but we don't want to require people to have
// to know the current `subscription` when they're just using this function to
// update the permissions of an existing membership row.
- const dbType = await getDBType();
while (insertRows.length > 0) {
const batch = insertRows.splice(0, membershipInsertBatchSize);
const query = SQL`
INSERT INTO memberships (user, thread, role, creation_time, subscription,
permissions, permissions_for_children, last_message, last_read_message)
VALUES ${batch}
- `;
- if (dbType === 'mysql5.7') {
- query.append(SQL`
- ON DUPLICATE KEY UPDATE
- subscription = IF(
- (role <= 0 AND VALUES(role) > 0)
- OR (role > 0 AND VALUES(role) <= 0),
- VALUES(subscription),
- subscription
- ),
- role = VALUES(role),
- permissions = VALUES(permissions),
- permissions_for_children = VALUES(permissions_for_children)
- `);
- } else {
- query.append(SQL`
ON DUPLICATE KEY UPDATE
subscription = IF(
(role <= 0 AND VALUE(role) > 0)
@@ -988,8 +934,7 @@
role = VALUE(role),
permissions = VALUE(permissions),
permissions_for_children = VALUE(permissions_for_children)
- `);
- }
+ `;
await dbQuery(query);
}
}
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,7 +31,6 @@
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 {
@@ -532,15 +531,9 @@
LEFT JOIN roles r ON r.id = t.default_role
WHERE t.id = ${request.threadID}
`;
- const [[result], dbType] = await Promise.all([
- dbQuery(rolePermissionsQuery),
- getDBType(),
- ]);
+ const [result] = await dbQuery(rolePermissionsQuery);
if (result.length > 0) {
- rolePermissions =
- dbType === 'mysql5.7'
- ? result[0].permissions
- : JSON.parse(result[0].permissions);
+ rolePermissions = JSON.parse(result[0].permissions);
}
}
if (!rolePermissions) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 6:56 PM (21 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591402
Default Alt Text
D4835.diff (32 KB)
Attached To
Mode
D4835: [keyserver] Get rid of all MySQL-specific query logic
Attached
Detach File
Event Timeline
Log In to Comment