From af19cbb098d6c8c1bea311b628ccb5f1ce897828 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Wed, 24 Nov 2010 20:14:54 +0100 Subject: Store last active time. --- parsing.c | 7 +++++-- pg.h | 6 ++++-- pg.pgc | 16 ++++++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/parsing.c b/parsing.c index c2e9f23..c57a242 100644 --- a/parsing.c +++ b/parsing.c @@ -370,15 +370,18 @@ void process() { } else printf("\tParsing %s\n", file->path); - long pos = pg_channel_file_get(channel_id, file); + long pos; + time_t time; + pg_channel_file_get(channel_id, file, &pos, &time); fseek(f, pos, SEEK_SET); + localtime_r(&time, &now_global); last_user = NULL; in_monolog = monolog_len = 0; process_file(f, channel, rs); - pg_channel_file_set(channel_id, file, ftell(f)); + pg_channel_file_set(channel_id, file, ftell(f), mktime(&now_global)); fclose(f); file = file->next; diff --git a/pg.h b/pg.h index 95a160c..6ff3178 100644 --- a/pg.h +++ b/pg.h @@ -1,6 +1,8 @@ #ifndef PG_H #define PG_H +#include + #include "channel.h" #include "user.h" #include "word.h" @@ -11,8 +13,8 @@ int pg_init(); int pg_upgrade(); void pg_dropall(); int pg_channel_get(struct channel_t *channel); -long pg_channel_file_get(int channel_id, struct channel_file_t *file); -void pg_channel_file_set(int channel_id, struct channel_file_t *file, long pos); +void pg_channel_file_get(int channel_id, struct channel_file_t *file, long *pos, time_t *time); +void pg_channel_file_set(int channel_id, struct channel_file_t *file, long pos, time_t time); void pg_user_set(int channel_id, struct user_t *user); void pg_users_get(int channel_id); void pg_word_set(int channel, struct word_t *word); diff --git a/pg.pgc b/pg.pgc index f9ebaac..ff9c182 100644 --- a/pg.pgc +++ b/pg.pgc @@ -53,6 +53,7 @@ int pg_init() { channel_id integer, path varchar, lastpos integer default 0, + lasttime integer, PRIMARY KEY (id), FOREIGN KEY (channel_id) REFERENCES channel (id) ); @@ -157,14 +158,15 @@ int pg_channel_get(struct channel_t *channel) { return id; } -long pg_channel_file_get(int channel_id, struct channel_file_t *file) { +void pg_channel_file_get(int channel_id, struct channel_file_t *file, long *pos, time_t *time) { EXEC SQL BEGIN DECLARE SECTION; int id = channel_id; const char *path = file->path; long lastpos = 0; + int lasttime = 0; EXEC SQL END DECLARE SECTION; - EXEC SQL SELECT lastpos INTO :lastpos FROM channel_file WHERE channel_id = :id AND path = :path; + EXEC SQL SELECT lastpos, lasttime INTO :lastpos, :lasttime FROM channel_file WHERE channel_id = :id AND path = :path; int do_insert = iserror() && testerror("02000"); if(iserror() && !do_insert) { @@ -178,19 +180,21 @@ long pg_channel_file_get(int channel_id, struct channel_file_t *file) { EXEC SQL INSERT INTO channel_file (channel_id, path) VALUES (:id, :path); if(iserror()) sqlprint(); EXEC SQL COMMIT; + } else { + *pos = lastpos; + *time = lasttime; } - - return lastpos; } -void pg_channel_file_set(int channel_id, struct channel_file_t *file, long pos) { +void pg_channel_file_set(int channel_id, struct channel_file_t *file, long pos, time_t time) { EXEC SQL BEGIN DECLARE SECTION; int id = channel_id; const char *path = file->path; long lastpos = pos; + int lasttime = time; EXEC SQL END DECLARE SECTION; - EXEC SQL UPDATE channel_file SET lastpos = :lastpos WHERE channel_id = :id AND path = :path; + EXEC SQL UPDATE channel_file SET lastpos = :lastpos, lasttime = :lasttime WHERE channel_id = :id AND path = :path; EXEC SQL COMMIT; } -- cgit v1.2.3