From d9c18a6072521bb44418830d2ba1cda14389af20 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 15 Feb 2013 14:22:23 -0500 Subject: Store hashes of the last commit instead of the last commit --- modules/database/db_sql.cpp | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'modules/database/db_sql.cpp') diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp index 74166d6dc..3bb0efde2 100644 --- a/modules/database/db_sql.cpp +++ b/modules/database/db_sql.cpp @@ -104,14 +104,11 @@ class DBSQL : public Module, public Pipe if (this->sql) { - Data *data = new Data(); - obj->Serialize(*data); + Data data; + obj->Serialize(data); if (obj->IsCached(data)) - { - delete data; continue; - } obj->UpdateCache(data); @@ -119,12 +116,18 @@ class DBSQL : public Module, public Pipe if (!s_type) continue; - std::vector create = this->sql->CreateTable(this->prefix + s_type->GetName(), *data); + std::vector create = this->sql->CreateTable(this->prefix + s_type->GetName(), data); for (unsigned i = 0; i < create.size(); ++i) this->RunBackground(create[i]); - Query insert = this->sql->BuildInsert(this->prefix + s_type->GetName(), obj->id, *data); - this->RunBackground(insert, new ResultSQLSQLInterface(this, obj)); + Query insert = this->sql->BuildInsert(this->prefix + s_type->GetName(), obj->id, data); + if (this->loaded) + this->RunBackground(insert, new ResultSQLSQLInterface(this, obj)); + else + /* If we aren't loading these objects then we are importing them, so don't do asynchronous + * queries in case for some reason the core has to shut down, it will cut short the import + */ + this->sql->RunQuery(insert); } } @@ -209,13 +212,13 @@ class DBSQL : public Module, public Pipe for (int j = 0; j < res.Rows(); ++j) { - Data *data = new Data(); + Data data; const std::map &row = res.Row(j); for (std::map::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit) - (*data)[rit->first] << rit->second; + data[rit->first] << rit->second; - Serializable *obj = sb->Unserialize(NULL, *data); + Serializable *obj = sb->Unserialize(NULL, data); try { if (obj) @@ -227,9 +230,14 @@ class DBSQL : public Module, public Pipe } if (obj) - obj->UpdateCache(data); /* We know this is the most up to date copy */ - else - delete data; + { + Data data2; + /* The Unserialize operation is destructive so rebuild the data for UpdateCache */ + for (std::map::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit) + if (rit->first != "id" && rit->first != "timestamp") + data2[rit->first] << rit->second; + obj->UpdateCache(data2); /* We know this is the most up to date copy */ + } } } }; -- cgit