turn on feature where sent messages are marked rather than deleted.

Make default 'epoch' rather than NULL so constraint will work to
prevent duplicates, and fix insertion SQL to not violate constraint.
This commit is contained in:
Eric House 2013-09-25 06:38:10 -07:00
parent fb59aa4907
commit 31fa2ea442
4 changed files with 23 additions and 8 deletions

View file

@ -56,7 +56,7 @@ CPPFLAGS += -DSVN_REV=\"$(shell cat $(GITINFO) 2>/dev/null || echo -n $(HASH) )\
CPPFLAGS += $(shell pkg-config --cflags glib-2.0)
# CPPFLAGS += -DLOG_UDP_PACKETS
# CPPFLAGS += -DDO_HTTP
# CPPFLAGS += -DHAVE_STIME
CPPFLAGS += -DHAVE_STIME
# turn on semaphore debugging
# CPPFLAGS += -DDEBUG_LOCKS

View file

@ -998,15 +998,23 @@ DBMgr::StoreMessage( const char* const connName, int hid,
size_t newLen;
const char* fmt = "INSERT INTO " MSGS_TABLE " "
"(connname, hid, devid, token, %s, msglen) "
"VALUES( '%s', %d, %d, "
"SELECT '%s', %d, %d, "
"(SELECT tokens[%d] from " GAMES_TABLE " where connname='%s'), "
"%s'%s', %d)";
"%s'%s', %d "
;
StrWPF query;
if ( m_useB64 ) {
gchar* b64 = g_base64_encode( buf, len );
query.printf( fmt, "msg64", connName, hid, devID, hid, connName,
"", b64, len );
query.printf( " WHERE NOT EXISTS (SELECT 1 FROM " MSGS_TABLE
" WHERE connname='%s' AND hid=%d AND msg64='%s'"
#ifdef HAVE_STIME
" AND stime='epoch'"
#endif
" );", connName, hid, b64 );
g_free( b64 );
} else {
uint8_t* bytes = PQescapeByteaConn( getThreadConn(), buf,

View file

@ -28,6 +28,7 @@ import mykey
k_shelfFile = path.splitext( path.basename( sys.argv[0]) )[0] + ".shelf"
k_SENT = 'SENT'
g_useStime = True
g_con = None
g_sent = None
g_debug = False
@ -57,8 +58,10 @@ def init():
def getPendingMsgs( con, typ ):
cur = con.cursor()
query = """SELECT %s FROM msgs
WHERE devid IN (SELECT id FROM devices WHERE devtypes[1]=%d and NOT unreg)
query = "SELECT %s FROM msgs WHERE "
if g_useStime:
query += " stime = 'epoch' AND "
query += """ devid IN (SELECT id FROM devices WHERE devtypes[1]=%d and NOT unreg)
AND (connname IS NULL OR NOT connname IN (SELECT connname FROM games WHERE dead));"""
cur.execute(query % (",".join( g_columns ), typ))
@ -83,7 +86,10 @@ def addClntVers( con, rows ):
def deleteMsgs( con, msgIDs ):
if 0 < len( msgIDs ):
query = "DELETE from msgs where id in (%s);" % ",".join(msgIDs)
if g_useStime:
query = "UPDATE msgs SET stime = 'now' where id in (%s);" % ",".join(msgIDs)
else:
query = "DELETE from msgs where id in (%s);" % ",".join(msgIDs)
try:
cur = con.cursor()
cur.execute(query)

View file

@ -39,8 +39,9 @@ echo "SELECT dead as d,connname,cid,room,lang as lg,clntVers as cv ,ntotal as t,
# Messages
echo "SELECT connname, hid, devid, count(*), sum(msglen) "\
"FROM msgs where connname in (SELECT connname from games where not games.dead group by connname) "\
"OR devid IN (SELECT unnest(devids) from games where not games.dead) "\
"FROM msgs WHERE stime = 'epoch' "\
"AND (connname IN (SELECT connname from games where not games.dead group by connname) "\
"OR devid IN (SELECT unnest(devids) from games where not games.dead)) "\
"GROUP BY connname, hid, devid ORDER BY connname LIMIT $LIMIT;" \
| psql xwgames