/* Schedule the dumps */
schedulerecurring(time(NULL)+DUMPINTERVAL,0,DUMPINTERVAL,chanservdumpstuff,NULL);
+ schedulerecurring(time(NULL)+5,0,5,csdb_flushchannelcounters,NULL);
chanserv_init_status = CS_INIT_NOUSER;
}
void _fini() {
+ csdb_flushchannelcounters(NULL);
+
dbfreeid(q9dbid);
deleteallschedules(cs_hourlyfunc);
deleteallschedules(chanservreguser);
deleteallschedules(chanservdumpstuff);
deleteallschedules(chanservdgline);
+ deleteallschedules(csdb_flushchannelcounters);
if (chanservext>-1 && chanservnext>-1 && chanservaext>-1) {
int i;
char *csdb_gethelpstr(char *command, int language);
void csdb_createmail(reguser *rup, int type);
void csdb_dohelp(nick *np, Command *cmd);
+void csdb_flushchannelcounters(void *arg);
#define q9asyncquery(handler, tag, format, ...) dbasyncqueryi(q9dbid, handler, tag, format , ##__VA_ARGS__)
#define q9a_asyncquery(handler, tag, format, ...) dbasyncqueryi(q9adbid, handler, tag, format , ##__VA_ARGS__)
escwelcome,esctopic,esckey,escreason,esccomment,(intmax_t)rcp->ltimestamp,rcp->ID);
}
+#define CHANNELCOUNTER_BUFSIZE 512
+#define CHANNELCOUNTER_MAX 512
+
+static int channelcounter_count = 0;
+static char channelcounter_bufs[CHANNELCOUNTER_MAX][CHANNELCOUNTER_BUFSIZE];
+
+void csdb_flushchannelcounters(void *arg) {
+ int i;
+
+ if(!channelcounter_count)
+ return;
+
+ dbquery("BEGIN TRANSACTION;");
+
+ for(i=0;i<channelcounter_count;i++)
+ dbquery("%s", channelcounter_bufs[i]);
+
+ dbquery("COMMIT;");
+
+ channelcounter_count = 0;
+}
+
void csdb_updatechannelcounters(regchan *rcp) {
- dbquery("UPDATE chanserv.channels SET "
+ if(channelcounter_count == CHANNELCOUNTER_MAX)
+ csdb_flushchannelcounters(NULL);
+
+ snprintf(channelcounter_bufs[channelcounter_count], CHANNELCOUNTER_BUFSIZE - 1, "UPDATE chanserv.channels SET "
"lastactive=%lu, totaljoins=%u,"
"tripjoins=%u, maxusers=%u, tripusers=%u "
"WHERE ID=%u",
rcp->totaljoins,rcp->tripjoins,
rcp->maxusers,rcp->tripusers,
rcp->ID);
+
+ channelcounter_count++;
}
void csdb_updatechanneltimestamp(regchan *rcp) {