don't save duplicate devIDs

There's likely a bug in Android now where I'm registering over and
over though the fcm id hasn't been changed. That's wrong, but it's
also wrong (and filling up the db) to register a duplicate as if it
were new. So stop that.
This commit is contained in:
Eric House 2019-02-01 12:13:05 -08:00 committed by Eric House
parent 6853b203a1
commit 940977718e
3 changed files with 13 additions and 5 deletions

View file

@ -457,7 +457,8 @@ DBMgr::ReregisterDevice( DevIDRelay relayID, const DevID* host,
.appendParam( host->m_devIDType )
.appendParam( host->m_devIDString.c_str() );
formatUpdate( qb, true, desc, clientVersion, model, osVers, variant, relayID );
formatUpdate( qb, true, desc, clientVersion, model, osVers, variant, relayID,
host->m_devIDString.c_str() );
qb.finish();
execParams( qb );
}
@ -480,7 +481,7 @@ DBMgr::UpdateDevice( DevIDRelay relayID, const char* const desc,
QueryBuilder qb;
qb.appendQueryf( "UPDATE " DEVICES_TABLE " SET " );
formatUpdate( qb, false, desc, clientVersion, model, osVers,
variant, relayID );
variant, relayID, NULL );
qb.finish();
execParams( qb );
}
@ -498,7 +499,7 @@ DBMgr::formatUpdate( QueryBuilder& qb,
bool append, const char* const desc,
int clientVersion, const char* const model,
const char* const osVers, const char* const variant,
DevIDRelay relayID )
DevIDRelay relayID, const char* newDevID )
{
if ( append ) {
qb.appendQueryf( "mtimes=array_prepend('now', mtimes)" ); // FIXME: too many
@ -524,8 +525,15 @@ DBMgr::formatUpdate( QueryBuilder& qb,
qb.appendQueryf( ", variant=$$" )
.appendParam( variant );
}
qb.appendQueryf( " WHERE id = $$" )
.appendParam( relayID );
if ( !!newDevID ) {
assert( append );
qb.appendQueryf( " AND NOT devids[1] = $$" )
.appendParam( newDevID );
}
}
HostID

View file

@ -177,7 +177,7 @@ class DBMgr {
void formatUpdate( QueryBuilder& qb, bool append, const char* const desc,
int clientVersion, const char* const model,
const char* const osVers, const char* const variant,
DevIDRelay relayID );
DevIDRelay relayID, const char* newDevID );
PGconn* getThreadConn( void );

View file

@ -67,7 +67,7 @@ echo "SELECT id,connName,hid as h,token,ctime,stime,devid,msg64 "\
| psql xwgames
# Devices
LINE="SELECT id, model, osvers, array_length(mtimes, 1) as mcnt, mtimes[1] as mtime, array_length(devTypes, 1) as dcnt, devTypes[1] as dTyp, devids[1] as devid FROM devices "
LINE="SELECT id, model, osvers, array_length(mtimes, 1) as mcnt, mtimes[1] as mtime, array_length(devTypes, 1) as dcnt, devTypes as dTyps, devids[1] as devid_1 FROM devices "
if [ -n "$FILTER_DEVS" ]; then
LINE="${LINE} WHERE id IN (select UNNEST(devids) FROM games $QUERY)"
fi