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;
|
const MAX_BUFFER_TIME = 120000;
|
||||||
|
|
||||||
class ChatMessageBuffer {
|
class ChatMessageBuffer {
|
||||||
constructor() {
|
constructor(socketEvents) {
|
||||||
this.buffer = new Map();
|
this.buffer = new Map();
|
||||||
this.timestamps = new Map();
|
this.timestamps = new Map();
|
||||||
|
|
||||||
this.cleanBuffer = this.cleanBuffer.bind(this);
|
this.cleanBuffer = this.cleanBuffer.bind(this);
|
||||||
this.cleanLoop = setInterval(this.cleanBuffer, 3 * 60 * 1000);
|
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) {
|
async getMessages(cid, limit = 30) {
|
||||||
|
@ -50,13 +53,17 @@ class ChatMessageBuffer {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async addMessage(
|
async broadcastChatMessage(
|
||||||
name,
|
name,
|
||||||
message,
|
message,
|
||||||
cid,
|
cid,
|
||||||
uid,
|
uid,
|
||||||
flag,
|
flag = 'xx',
|
||||||
|
sendapi = true,
|
||||||
) {
|
) {
|
||||||
|
if (message.length > 200) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Message.create({
|
Message.create({
|
||||||
name,
|
name,
|
||||||
flag,
|
flag,
|
||||||
|
@ -71,6 +78,27 @@ class ChatMessageBuffer {
|
||||||
id: cid,
|
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);
|
const messages = this.buffer.get(cid);
|
||||||
if (messages) {
|
if (messages) {
|
||||||
messages.push([
|
messages.push([
|
||||||
|
|
|
@ -74,7 +74,7 @@ export class ChatProvider {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
this.mutedCountries = [];
|
this.mutedCountries = [];
|
||||||
this.chatMessageBuffer = new ChatMessageBuffer();
|
this.chatMessageBuffer = new ChatMessageBuffer(socketEvents);
|
||||||
this.clearOldMessages = this.clearOldMessages.bind(this);
|
this.clearOldMessages = this.clearOldMessages.bind(this);
|
||||||
|
|
||||||
socketEvents.on('recvChatMessage', async (user, message, channelId) => {
|
socketEvents.on('recvChatMessage', async (user, message, channelId) => {
|
||||||
|
@ -503,32 +503,8 @@ export class ChatProvider {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
broadcastChatMessage(
|
broadcastChatMessage(...args) {
|
||||||
name,
|
return this.chatMessageBuffer.broadcastChatMessage(...args);
|
||||||
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,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async checkIfMuted(uid) {
|
static async checkIfMuted(uid) {
|
||||||
|
|
|
@ -33,17 +33,19 @@ class Ranks {
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateRanking() {
|
async updateRanking() {
|
||||||
logger.info('Update pixel rankings');
|
|
||||||
if (socketEvents.amIImportant()) {
|
if (socketEvents.amIImportant()) {
|
||||||
|
logger.info('Update pixel rankings in SQL');
|
||||||
// recalculate ranking column
|
// recalculate ranking column
|
||||||
await sequelize.query(
|
await sequelize.query(
|
||||||
// eslint-disable-next-line max-len
|
// 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(
|
await sequelize.query(
|
||||||
// eslint-disable-next-line max-len
|
// 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
|
// populate dictionaries
|
||||||
const ranking = await RegUser.findAll({
|
const ranking = await RegUser.findAll({
|
||||||
|
@ -64,7 +66,9 @@ class Ranks {
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
limit: 100,
|
limit: 100,
|
||||||
where: { id: { [Sequelize.Op.notIn]: [51, 1] } },
|
where: {
|
||||||
|
ranking: { [Sequelize.Op.not]: null },
|
||||||
|
},
|
||||||
order: ['ranking'],
|
order: ['ranking'],
|
||||||
raw: true,
|
raw: true,
|
||||||
});
|
});
|
||||||
|
@ -86,7 +90,9 @@ class Ranks {
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
limit: 100,
|
limit: 100,
|
||||||
where: { id: { [Sequelize.Op.notIn]: [51, 1] } },
|
where: {
|
||||||
|
dailyRanking: { [Sequelize.Op.not]: null },
|
||||||
|
},
|
||||||
order: ['dailyRanking'],
|
order: ['dailyRanking'],
|
||||||
raw: true,
|
raw: true,
|
||||||
});
|
});
|
||||||
|
|
|
@ -42,7 +42,7 @@ function generateMainPage(req) {
|
||||||
const ssvR = {
|
const ssvR = {
|
||||||
...ssv,
|
...ssv,
|
||||||
shard: (host.startsWith(`${socketEvents.thisShard}.`))
|
shard: (host.startsWith(`${socketEvents.thisShard}.`))
|
||||||
? '' : socketEvents.getLowestActiveShard(),
|
? null : socketEvents.getLowestActiveShard(),
|
||||||
lang: lang === 'default' ? 'en' : lang,
|
lang: lang === 'default' ? 'en' : lang,
|
||||||
};
|
};
|
||||||
const scripts = (assets[`client-${lang}`])
|
const scripts = (assets[`client-${lang}`])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user