Skip to content

Commit

Permalink
feat(activity): Remove db stats
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed Dec 18, 2019
1 parent ff878e5 commit 8d17416
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 76 deletions.
39 changes: 2 additions & 37 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { ModerationService } from './moderation/services/Moderation';
import { MusicCache } from './music/cache/MusicCache';
import { MusicService } from './music/services/MusicService';
import { botDefaultSettings, BotSettingsObject, guildDefaultSettings } from './settings';
import { BotType, ChannelType, GatewayInfo, LavaPlayerManager } from './types';
import { BotType, ChannelType, LavaPlayerManager } from './types';

i18n.configure({
locales: ['cs', 'de', 'en', 'es', 'fr', 'it', 'ja', 'nl', 'pl', 'pt', 'pt_BR', 'ro', 'ru', 'tr'],
Expand Down Expand Up @@ -114,11 +114,6 @@ export class IMClient extends Client {
cmdHttpErrors: Map<number, number>;
};

private counts: {
cachedAt: Moment;
guilds: number;
members: number;
};
public disabledGuilds: Set<string> = new Set();

public constructor({ version, token, type, instance, shardId, shardCount, flags, config }: ClientOptions) {
Expand Down Expand Up @@ -148,11 +143,6 @@ export class IMClient extends Client {
cmdErrors: 0,
cmdHttpErrors: new Map()
};
this.counts = {
cachedAt: moment.unix(0),
guilds: 0,
members: 0
};

this.version = version;
this.type = type;
Expand Down Expand Up @@ -544,25 +534,6 @@ export class IMClient extends Client {
});
}

public async getCounts() {
// If cached data is older than 12 hours, update it
if (
moment()
.subtract(4, 'hours')
.isAfter(this.counts.cachedAt)
) {
console.log('Fetching data counts from DB...');
const stats = await this.db.getDbStats();
this.counts = {
cachedAt: moment(),
guilds: stats.guilds,
members: stats.members
};
}

return this.counts;
}

public async setActivity() {
const status = this.settings.activityStatus;

Expand All @@ -571,8 +542,6 @@ export class IMClient extends Client {
return;
}

const counts = await this.getCounts();

const type =
this.settings.activityType === 'playing'
? 0
Expand All @@ -584,11 +553,7 @@ export class IMClient extends Client {
? 3
: 0;

let name = `invitemanager.co - ${counts.guilds} servers!`;
if (this.settings.activityMessage) {
name = this.settings.activityMessage.replace(/{serverCount}/gi, counts.guilds.toString());
}

const name = this.settings.activityMessage || `docs.invitemanager.co!`;
const url = this.settings.activityUrl;

this.editStatus(status, { name, type, url });
Expand Down
21 changes: 0 additions & 21 deletions src/framework/commands/info/botInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export default class extends Command {
): Promise<any> {
const lang = settings.lang;

const counts = await this.client.getCounts();

const embed = this.createEmbed();

// Version
Expand All @@ -45,31 +43,12 @@ export default class extends Command {
inline: true
});

// Guild count
embed.fields.push({
name: t('cmd.botInfo.guilds'),
value: counts.guilds.toString(),
inline: true
});

// Member count
embed.fields.push({
name: t('cmd.botInfo.members'),
value: counts.members.toString(),
inline: true
});

// Shard info
embed.fields.push({
name: t('cmd.botInfo.shards.current'),
value: `${this.client.shardId} (${this.client.db.getDbShardForGuild(guild.id)})`,
inline: true
});
embed.fields.push({
name: t('cmd.botInfo.shards.total'),
value: this.client.shardCount.toString(),
inline: true
});

// Premium
embed.fields.push({
Expand Down
6 changes: 0 additions & 6 deletions src/framework/models/DBStat.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/framework/services/DatabaseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { getShardIdForGuild } from '../../util';
import { BotSetting } from '../models/BotSetting';
import { Channel } from '../models/Channel';
import { CommandUsage } from '../models/CommandUsage';
import { DBStat } from '../models/DBStat';
import { Guild } from '../models/Guild';
import { GuildSetting } from '../models/GuildSetting';
import { Incident } from '../models/Incident';
Expand Down Expand Up @@ -799,17 +798,6 @@ export class DatabaseService {
await this.insertOrUpdate(TABLE.incidents, ['guildId', 'error', 'details'], [], indicents, i => i.guildId);
}

// ------------
// DB stats
// ------------
public async getDbStats() {
const stats = await this.findMany<DBStat>(GLOBAL_SHARD_ID, TABLE.dbStats, '`key` IN(?)', [['guilds', 'members']]);
return {
guilds: stats.find(stat => stat.key === 'guilds').value,
members: stats.find(stat => stat.key === 'members').value
};
}

// ---------------
// Music nodes
// ---------------
Expand Down

0 comments on commit 8d17416

Please sign in to comment.