mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 18:35:11 +00:00
[MOD] Make the cleanup *do a thing*.
This commit is contained in:
parent
37155316b2
commit
10e140e2a2
5 changed files with 62 additions and 2 deletions
|
|
@ -77,6 +77,8 @@ Main(void)
|
||||||
cron = CronCreate( 10 SECONDS );
|
cron = CronCreate( 10 SECONDS );
|
||||||
CronEvery(cron, 30 MINUTES, ParseeCleanup, conf.handlerArgs);
|
CronEvery(cron, 30 MINUTES, ParseeCleanup, conf.handlerArgs);
|
||||||
|
|
||||||
|
CronStart(cron);
|
||||||
|
|
||||||
Log(LOG_NOTICE, "Creating XMPP listener thread...");
|
Log(LOG_NOTICE, "Creating XMPP listener thread...");
|
||||||
if (pthread_create(&xmpp_thr, NULL, ParseeXMPPThread, conf.handlerArgs))
|
if (pthread_create(&xmpp_thr, NULL, ParseeXMPPThread, conf.handlerArgs))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
#include <Parsee.h>
|
#include <Parsee.h>
|
||||||
|
|
||||||
#include <Cytoplasm/Memory.h>
|
#include <Cytoplasm/Memory.h>
|
||||||
|
#include <Cytoplasm/Json.h>
|
||||||
|
#include <Cytoplasm/Util.h>
|
||||||
#include <Cytoplasm/Log.h>
|
#include <Cytoplasm/Log.h>
|
||||||
|
#include <Cytoplasm/Str.h>
|
||||||
|
|
||||||
#include <Routes.h>
|
#include <Routes.h>
|
||||||
|
|
||||||
|
|
@ -49,7 +52,50 @@ void
|
||||||
ParseeCleanup(void *datp)
|
ParseeCleanup(void *datp)
|
||||||
{
|
{
|
||||||
ParseeData *data = datp;
|
ParseeData *data = datp;
|
||||||
|
Array *chats;
|
||||||
|
char *chat;
|
||||||
|
size_t i;
|
||||||
|
uint64_t ts = UtilTsMillis();
|
||||||
|
|
||||||
Log(LOG_NOTICE, "Cleaning up...");
|
Log(LOG_NOTICE, "Cleaning up...");
|
||||||
|
chats = DbList(data->db, 1, "chats");
|
||||||
|
|
||||||
|
for (i = 0; i < ArraySize(chats); i++)
|
||||||
|
{
|
||||||
|
DbRef *ref;
|
||||||
|
HashMap *json, *stanzas;
|
||||||
|
char *stanza;
|
||||||
|
JsonValue *val;
|
||||||
|
Array *to_delete;
|
||||||
|
size_t j;
|
||||||
|
|
||||||
|
chat = ArrayGet(chats, i);
|
||||||
|
ref = DbLock(data->db, 2, "chats", chat);
|
||||||
|
json = DbJson(ref);
|
||||||
|
stanzas = JsonValueAsObject(HashMapGet(json, "stanzas"));
|
||||||
|
to_delete = ArrayCreate();
|
||||||
|
while (HashMapIterate(stanzas, &stanza, (void **) &val))
|
||||||
|
{
|
||||||
|
HashMap *obj = JsonValueAsObject(val);
|
||||||
|
uint64_t age = JsonValueAsInteger(HashMapGet(obj, "age"));
|
||||||
|
uint64_t dur = ts - age;
|
||||||
|
|
||||||
|
if ((dur > (5 MINUTES)))
|
||||||
|
{
|
||||||
|
ArrayAdd(to_delete, StrDuplicate(stanza));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (j = 0; j < ArraySize(to_delete); j++)
|
||||||
|
{
|
||||||
|
stanza = ArrayGet(to_delete, j);
|
||||||
|
JsonValueFree(HashMapDelete(stanzas, stanza));
|
||||||
|
Free(stanza);
|
||||||
|
}
|
||||||
|
ArrayFree(to_delete);
|
||||||
|
|
||||||
|
DbUnlock(data->db, ref);
|
||||||
|
}
|
||||||
|
DbListFree(chats);
|
||||||
/* TODO */
|
/* TODO */
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <Cytoplasm/Memory.h>
|
#include <Cytoplasm/Memory.h>
|
||||||
#include <Cytoplasm/Json.h>
|
#include <Cytoplasm/Json.h>
|
||||||
|
#include <Cytoplasm/Util.h>
|
||||||
#include <Cytoplasm/Str.h>
|
#include <Cytoplasm/Str.h>
|
||||||
#include <Cytoplasm/Sha.h>
|
#include <Cytoplasm/Sha.h>
|
||||||
#include <Cytoplasm/Log.h>
|
#include <Cytoplasm/Log.h>
|
||||||
|
|
@ -544,8 +545,9 @@ ParseePushStanza(ParseeData *data, char *chat_id, char *stanza_id)
|
||||||
{
|
{
|
||||||
DbRef *ref;
|
DbRef *ref;
|
||||||
HashMap *j;
|
HashMap *j;
|
||||||
HashMap *stanzas;
|
HashMap *stanzas, *obj;
|
||||||
bool new_stanzas = false;
|
bool new_stanzas = false;
|
||||||
|
uint64_t age = UtilTsMillis();
|
||||||
if (!data || !chat_id || !stanza_id)
|
if (!data || !chat_id || !stanza_id)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|
@ -565,7 +567,9 @@ ParseePushStanza(ParseeData *data, char *chat_id, char *stanza_id)
|
||||||
new_stanzas = true;
|
new_stanzas = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonValueFree(HashMapSet(stanzas, stanza_id, JsonValueNull()));
|
obj = HashMapCreate();
|
||||||
|
HashMapSet(obj, "age", JsonValueInteger(age));
|
||||||
|
JsonValueFree(HashMapSet(stanzas, stanza_id, JsonValueObject(obj)));
|
||||||
|
|
||||||
if (new_stanzas)
|
if (new_stanzas)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <Cytoplasm/Memory.h>
|
#include <Cytoplasm/Memory.h>
|
||||||
#include <Cytoplasm/Str.h>
|
#include <Cytoplasm/Str.h>
|
||||||
|
#include <Cytoplasm/Log.h>
|
||||||
|
|
||||||
XMLElement *
|
XMLElement *
|
||||||
XMLCreateTag(char *name)
|
XMLCreateTag(char *name)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
#include <XML.h>
|
#include <XML.h>
|
||||||
|
|
||||||
|
#include <Cytoplasm/Log.h>
|
||||||
|
#include <Cytoplasm/Str.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
XMLElement *
|
XMLElement *
|
||||||
|
|
@ -72,6 +75,10 @@ XMLDecode(Stream *stream, bool autofree)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XML_LEXER_DATA:
|
case XML_LEXER_DATA:
|
||||||
|
if (!peek())
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
top = XMLCreateText(event->data);
|
top = XMLCreateText(event->data);
|
||||||
XMLAddChild(peek(), top);
|
XMLAddChild(peek(), top);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue