Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32980296
D8683.1768319537.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D8683.1768319537.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
@@ -886,15 +886,28 @@
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 [result] = await dbQuery(query);
+
+ if (result.affectedRows === 0) {
+ return {
+ newMessageInfos: [],
+ threadID,
+ };
+ }
+
const messageData = {
type: messageTypes.TOGGLE_PIN,
threadID,
@@ -904,30 +917,11 @@
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 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
Tue, Jan 13, 3:52 PM (10 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5927142
Default Alt Text
D8683.1768319537.diff (1 KB)
Attached To
Mode
D8683: [keyserver] Fix the pinned count MariaDB out of range issue
Attached
Detach File
Event Timeline
Log In to Comment