Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3516405
D8683.id29441.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D8683.id29441.diff
View Options
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
@@ -860,48 +860,38 @@
const pinnedValue = action === 'pin' ? 1 : 0;
const pinTimeValue = action === 'pin' ? Date.now() : null;
+ const pinnedCountValue = action === 'pin' ? 1 : -1;
- const togglePinQuery = SQL`
- UPDATE messages
- SET pinned = ${pinnedValue},
- pin_time = ${pinTimeValue}
- WHERE id = ${messageID}
- AND thread = ${threadID}
+ const query = SQL`
+ UPDATE messages AS m, threads AS t
+ SET m.pinned = ${pinnedValue},
+ m.pin_time = ${pinTimeValue},
+ t.pinned_count = t.pinned_count + ${pinnedCountValue}
+ WHERE m.id = ${messageID}
+ AND m.thread = ${threadID}
+ AND t.id = ${threadID}
+ AND m.pinned <> ${pinnedValue}
`;
- const messageData = {
- type: messageTypes.TOGGLE_PIN,
- threadID,
- targetMessageID: messageID,
- action,
- pinnedContent: getPinnedContentFromMessage(targetMessage),
- creatorID: viewer.userID,
- time: Date.now(),
- };
-
- let updateThreadQuery;
- if (action === 'pin') {
- updateThreadQuery = SQL`
- UPDATE threads
- SET pinned_count = pinned_count + 1
- WHERE id = ${threadID}
- `;
- } else {
- updateThreadQuery = SQL`
- UPDATE threads
- SET pinned_count = pinned_count - 1
- WHERE id = ${threadID}
- `;
- }
-
- const [{ threadInfos: serverThreadInfos }] = await Promise.all([
- fetchServerThreadInfos({ threadID }),
- dbQuery(togglePinQuery),
- dbQuery(updateThreadQuery),
- ]);
+ const [result] = await dbQuery(query);
- const newMessageInfos = await createMessages(viewer, [messageData]);
+ let newMessageInfos = [];
+ if (result.affectedRows > 0) {
+ const messageData = {
+ type: messageTypes.TOGGLE_PIN,
+ threadID,
+ targetMessageID: messageID,
+ action,
+ pinnedContent: getPinnedContentFromMessage(targetMessage),
+ creatorID: viewer.userID,
+ time: Date.now(),
+ };
+ newMessageInfos = await createMessages(viewer, [messageData]);
+ }
+ const { threadInfos: serverThreadInfos } = await fetchServerThreadInfos({
+ threadID,
+ });
const time = Date.now();
const updates = [];
for (const member of serverThreadInfos[threadID].members) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 2:20 PM (18 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2694864
Default Alt Text
D8683.id29441.diff (2 KB)
Attached To
Mode
D8683: [keyserver] Fix the pinned count MariaDB out of range issue
Attached
Detach File
Event Timeline
Log In to Comment