Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3562148
D4522.id.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
D4522.id.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
@@ -108,14 +108,25 @@
LEFT JOIN messages m ON m.id = n.message
LEFT JOIN uploads up
ON m.type IN (${[messageTypes.IMAGES, messageTypes.MULTIMEDIA]})
- AND JSON_CONTAINS(m.content, CAST(up.id as JSON), '$')
+ `;
+ const dbType = await getDBType();
+ if (dbType === 'mysql5.7') {
+ collapseQuery.append(SQL`
+ AND JSON_CONTAINS(m.content, CAST(up.id AS JSON), '$')
+ `);
+ } else {
+ collapseQuery.append(SQL`
+ AND JSON_CONTAINS(m.content, up.id, '$')
+ `);
+ }
+ collapseQuery.append(SQL`
LEFT JOIN memberships mm ON mm.thread = m.thread AND mm.user = n.user
LEFT JOIN memberships stm
ON m.type = ${messageTypes.CREATE_SUB_THREAD}
AND stm.thread = m.content AND stm.user = n.user
WHERE n.rescinded = 0 AND
JSON_EXTRACT(mm.permissions, ${visibleExtractString}) IS TRUE AND
- `;
+ `);
collapseQuery.append(mergeOrConditions(sqlTuples));
collapseQuery.append(SQL`ORDER BY m.time DESC`);
const [collapseResult] = await dbQuery(collapseQuery);
@@ -298,13 +309,24 @@
FROM messages m
LEFT JOIN uploads up
ON m.type IN (${[messageTypes.IMAGES, messageTypes.MULTIMEDIA]})
- AND JSON_CONTAINS(m.content, CAST(up.id as JSON), '$')
+ `;
+ const dbType = await getDBType();
+ if (dbType === 'mysql5.7') {
+ query.append(SQL`
+ AND JSON_CONTAINS(m.content, CAST(up.id AS JSON), '$')
+ `);
+ } else {
+ query.append(SQL`
+ AND JSON_CONTAINS(m.content, up.id, '$')
+ `);
+ }
+ query.append(SQL`
LEFT JOIN memberships mm
ON mm.thread = m.thread AND mm.user = ${viewerID}
LEFT JOIN memberships stm ON m.type = ${messageTypes.CREATE_SUB_THREAD}
AND stm.thread = m.content AND stm.user = ${viewerID}
WHERE JSON_EXTRACT(mm.permissions, ${visibleExtractString}) IS TRUE AND
- `;
+ `);
query.append(selectionClause);
// - We specify a ridiculously high LIMIT here to force MariaDB to maintain
// the ORDER BY. Otherwise the query optimizer will assume that the order
@@ -528,12 +550,23 @@
FROM messages m
LEFT JOIN uploads up
ON m.type IN (${[messageTypes.IMAGES, messageTypes.MULTIMEDIA]})
- AND JSON_CONTAINS(m.content, CAST(up.id as JSON), '$')
+ `;
+ const dbType = await getDBType();
+ if (dbType === 'mysql5.7') {
+ query.append(SQL`
+ AND JSON_CONTAINS(m.content, CAST(up.id AS JSON), '$')
+ `);
+ } else {
+ query.append(SQL`
+ AND JSON_CONTAINS(m.content, up.id, '$')
+ `);
+ }
+ query.append(SQL`
LEFT JOIN memberships mm ON mm.thread = m.thread AND mm.user = ${viewerID}
LEFT JOIN memberships stm ON m.type = ${messageTypes.CREATE_SUB_THREAD}
AND stm.thread = m.content AND stm.user = ${viewerID}
WHERE JSON_EXTRACT(mm.permissions, ${visibleExtractString}) IS TRUE AND
- `;
+ `);
query.append(selectionClause);
query.append(SQL`
ORDER BY m.thread, m.time DESC
@@ -612,13 +645,24 @@
FROM messages m
LEFT JOIN uploads up
ON m.type IN (${[messageTypes.IMAGES, messageTypes.MULTIMEDIA]})
- AND JSON_CONTAINS(m.content, CAST(up.id as JSON), '$')
+ `;
+ const dbType = await getDBType();
+ if (dbType === 'mysql5.7') {
+ query.append(SQL`
+ AND JSON_CONTAINS(m.content, CAST(up.id AS JSON), '$')
+ `);
+ } else {
+ query.append(SQL`
+ AND JSON_CONTAINS(m.content, up.id, '$')
+ `);
+ }
+ query.append(SQL`
LEFT JOIN memberships mm ON mm.thread = m.thread AND mm.user = ${viewerID}
LEFT JOIN memberships stm ON m.type = ${messageTypes.CREATE_SUB_THREAD}
AND stm.thread = m.content AND stm.user = ${viewerID}
WHERE m.user = ${viewerID} AND m.creation = ${creation} AND
JSON_EXTRACT(mm.permissions, ${visibleExtractString}) IS TRUE
- `;
+ `);
const [result] = await dbQuery(query);
if (result.length === 0) {
@@ -643,13 +687,24 @@
FROM messages m
LEFT JOIN uploads up
ON m.type IN (${[messageTypes.IMAGES, messageTypes.MULTIMEDIA]})
- AND JSON_CONTAINS(m.content, CAST(up.id as JSON), '$')
+ `;
+ const dbType = await getDBType();
+ if (dbType === 'mysql5.7') {
+ query.append(SQL`
+ AND JSON_CONTAINS(m.content, CAST(up.id AS JSON), '$')
+ `);
+ } else {
+ query.append(SQL`
+ AND JSON_CONTAINS(m.content, up.id, '$')
+ `);
+ }
+ query.append(SQL`
LEFT JOIN memberships mm ON mm.thread = m.thread AND mm.user = ${viewerID}
WHERE m.user = ${viewerID} AND m.thread = ${threadID} AND
m.type = ${messageType} AND
JSON_EXTRACT(m.content, ${entryIDExtractString}) = ${entryID} AND
JSON_EXTRACT(mm.permissions, ${visibleExtractString}) IS TRUE
- `;
+ `);
const [result] = await dbQuery(query);
if (result.length === 0) {
@@ -668,11 +723,22 @@
FROM messages m
LEFT JOIN uploads up
ON m.type IN (${[messageTypes.IMAGES, messageTypes.MULTIMEDIA]})
- AND JSON_CONTAINS(m.content, CAST(up.id as JSON), '$')
+ `;
+ const dbType = await getDBType();
+ if (dbType === 'mysql5.7') {
+ query.append(SQL`
+ AND JSON_CONTAINS(m.content, CAST(up.id AS JSON), '$')
+ `);
+ } else {
+ query.append(SQL`
+ AND JSON_CONTAINS(m.content, up.id, '$')
+ `);
+ }
+ query.append(SQL`
LEFT JOIN memberships stm ON m.type = ${messageTypes.CREATE_SUB_THREAD}
AND stm.thread = m.content AND stm.user = m.user
WHERE m.id IN (${messageIDs})
- `;
+ `);
const [result] = await dbQuery(query);
return result;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Dec 28, 9:47 AM (5 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2725560
Default Alt Text
D4522.id.diff (5 KB)
Attached To
Mode
D4522: [keyserver] Avoid JSON cast when using MariaDB
Attached
Detach File
Event Timeline
Log In to Comment