fix chat message storing for shards
dont show NULL in rankings
This commit is contained in:
parent
fc602934dc
commit
971531a3f6
|
@ -11,12 +11,15 @@ import { Message, Channel } from '../data/sql';
|
|||
const MAX_BUFFER_TIME = 120000;
|
||||
|
||||
class ChatMessageBuffer {
|
||||
constructor() {
|
||||
constructor(socketEvents) {
|
||||
this.buffer = new Map();
|
||||
this.timestamps = new Map();
|
||||
|
||||
this.cleanBuffer = this.cleanBuffer.bind(this);
|
||||
this.cleanLoop = setInterval(this.cleanBuffer, 3 * 60 * 1000);
|
||||
this.addMessage = this.addMessage.bind(this);
|
||||
this.socketEvents = socketEvents;
|
||||
socketEvents.on('chatMessage', this.addMessage);
|
||||
}
|
||||
|
||||
async getMessages(cid, limit = 30) {
|
||||
|
@ -50,13 +53,17 @@ class ChatMessageBuffer {
|
|||
);
|
||||
}
|
||||
|
||||
async addMessage(
|
||||
async broadcastChatMessage(
|
||||
name,
|
||||
message,
|
||||
cid,
|
||||
uid,
|
||||
flag,
|
||||
flag = 'xx',
|
||||
sendapi = true,
|
||||
) {
|
||||
if (message.length > 200) {
|
||||
return;
|
||||
}
|
||||
Message.create({
|
||||
name,
|
||||
flag,
|
||||
|
@ -71,6 +78,27 @@ class ChatMessageBuffer {
|
|||
id: cid,
|
||||
},
|
||||
});
|
||||
/*
|
||||
* goes through socket events and then comes
|
||||
* back at addMessage
|
||||
*/
|
||||
this.socketEvents.broadcastChatMessage(
|
||||
name,
|
||||
message,
|
||||
cid,
|
||||
uid,
|
||||
flag,
|
||||
sendapi,
|
||||
);
|
||||
}
|
||||
|
||||
async addMessage(
|
||||
name,
|
||||
message,
|
||||
cid,
|
||||
uid,
|
||||
flag,
|
||||
) {
|
||||
const messages = this.buffer.get(cid);
|
||||
if (messages) {
|
||||
messages.push([
|
||||
|
|
|
@ -74,7 +74,7 @@ export class ChatProvider {
|
|||
},
|
||||
];
|
||||
this.mutedCountries = [];
|
||||
this.chatMessageBuffer = new ChatMessageBuffer();
|
||||
this.chatMessageBuffer = new ChatMessageBuffer(socketEvents);
|
||||
this.clearOldMessages = this.clearOldMessages.bind(this);
|
||||
|
||||
socketEvents.on('recvChatMessage', async (user, message, channelId) => {
|
||||
|
@ -503,32 +503,8 @@ export class ChatProvider {
|
|||
return null;
|
||||
}
|
||||
|
||||
broadcastChatMessage(
|
||||
name,
|
||||
message,
|
||||
channelId,
|
||||
id,
|
||||
country = 'xx',
|
||||
sendapi = true,
|
||||
) {
|
||||
if (message.length > 250) {
|
||||
return;
|
||||
}
|
||||
this.chatMessageBuffer.addMessage(
|
||||
name,
|
||||
message,
|
||||
channelId,
|
||||
id,
|
||||
country,
|
||||
);
|
||||
socketEvents.broadcastChatMessage(
|
||||
name,
|
||||
message,
|
||||
channelId,
|
||||
id,
|
||||
country,
|
||||
sendapi,
|
||||
);
|
||||
broadcastChatMessage(...args) {
|
||||
return this.chatMessageBuffer.broadcastChatMessage(...args);
|
||||
}
|
||||
|
||||
static async checkIfMuted(uid) {
|
||||
|
|
|
@ -33,17 +33,19 @@ class Ranks {
|
|||
}
|
||||
|
||||
async updateRanking() {
|
||||
logger.info('Update pixel rankings');
|
||||
if (socketEvents.amIImportant()) {
|
||||
logger.info('Update pixel rankings in SQL');
|
||||
// recalculate ranking column
|
||||
await sequelize.query(
|
||||
// eslint-disable-next-line max-len
|
||||
'SET @r=0; UPDATE Users SET ranking= @r:= (@r + 1) ORDER BY totalPixels DESC;',
|
||||
'SET @r=0; UPDATE Users SET ranking= @r:= (@r + 1) WHERE totalPixels IS NOT NULL ORDER BY totalPixels DESC;',
|
||||
);
|
||||
await sequelize.query(
|
||||
// eslint-disable-next-line max-len
|
||||
'SET @r=0; UPDATE Users SET dailyRanking= @r:= (@r + 1) ORDER BY dailyTotalPixels DESC;',
|
||||
'SET @r=0; UPDATE Users SET dailyRanking= @r:= (@r + 1) WHERE dailyTotalPixels IS NOT NULL ORDER BY dailyTotalPixels DESC;',
|
||||
);
|
||||
} else {
|
||||
logger.info('Get pixel rankings from SQL');
|
||||
}
|
||||
// populate dictionaries
|
||||
const ranking = await RegUser.findAll({
|
||||
|
@ -64,7 +66,9 @@ class Ranks {
|
|||
],
|
||||
],
|
||||
limit: 100,
|
||||
where: { id: { [Sequelize.Op.notIn]: [51, 1] } },
|
||||
where: {
|
||||
ranking: { [Sequelize.Op.not]: null },
|
||||
},
|
||||
order: ['ranking'],
|
||||
raw: true,
|
||||
});
|
||||
|
@ -86,7 +90,9 @@ class Ranks {
|
|||
],
|
||||
],
|
||||
limit: 100,
|
||||
where: { id: { [Sequelize.Op.notIn]: [51, 1] } },
|
||||
where: {
|
||||
dailyRanking: { [Sequelize.Op.not]: null },
|
||||
},
|
||||
order: ['dailyRanking'],
|
||||
raw: true,
|
||||
});
|
||||
|
|
|
@ -42,7 +42,7 @@ function generateMainPage(req) {
|
|||
const ssvR = {
|
||||
...ssv,
|
||||
shard: (host.startsWith(`${socketEvents.thisShard}.`))
|
||||
? '' : socketEvents.getLowestActiveShard(),
|
||||
? null : socketEvents.getLowestActiveShard(),
|
||||
lang: lang === 'default' ? 'en' : lang,
|
||||
};
|
||||
const scripts = (assets[`client-${lang}`])
|
||||
|
|
Loading…
Reference in New Issue
Block a user