Spaces:
Sleeping
Sleeping
Sasha commited on
Commit ·
d931d22
1
Parent(s): 54a28a5
fix: logRolesBatch always updates roles, only preserves newer last_seen
Browse files- server/db.js +8 -2
server/db.js
CHANGED
|
@@ -833,10 +833,16 @@ export async function logRolesBatch(users) {
|
|
| 833 |
.in('username', uniqueChatUsers.map(u => u.username));
|
| 834 |
|
| 835 |
const existingMap = new Map((existingUsers || []).map(u => [u.username, new Date(u.last_seen).getTime()]));
|
| 836 |
-
|
|
|
|
|
|
|
| 837 |
const oldTime = existingMap.get(u.username) || 0;
|
| 838 |
const newTime = new Date(u.last_seen).getTime();
|
| 839 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
| 840 |
});
|
| 841 |
|
| 842 |
if (toUpsert.length > 0) {
|
|
|
|
| 833 |
.in('username', uniqueChatUsers.map(u => u.username));
|
| 834 |
|
| 835 |
const existingMap = new Map((existingUsers || []).map(u => [u.username, new Date(u.last_seen).getTime()]));
|
| 836 |
+
|
| 837 |
+
// Always update roles (is_mod/is_sub/is_vip), but only advance last_seen if newer
|
| 838 |
+
const toUpsert = uniqueChatUsers.map(u => {
|
| 839 |
const oldTime = existingMap.get(u.username) || 0;
|
| 840 |
const newTime = new Date(u.last_seen).getTime();
|
| 841 |
+
return {
|
| 842 |
+
...u,
|
| 843 |
+
// Keep last_seen as the newer of the two
|
| 844 |
+
last_seen: newTime > oldTime ? u.last_seen : (existingUsers || []).find(e => e.username === u.username)?.last_seen || u.last_seen
|
| 845 |
+
};
|
| 846 |
});
|
| 847 |
|
| 848 |
if (toUpsert.length > 0) {
|