summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-10-12 04:04:14 -0400
committerAdam <Adam@anope.org>2012-10-13 00:37:10 -0400
commit76a0471c291d2b8045b52ec8e9d683a38bff47ff (patch)
tree0e464d4c131796f223dfe3d82feb9862300b7d23
parente08422a4eafd7c1d317421ef4929a74f7005fd2d (diff)
Simplify the db_sql_live code since this isn't actually necessary. Fixes a problem internally ovwrwriting data on objects that we have modified and are queued because of assigning something to a serialize_obj reference
-rw-r--r--include/modules.h3
-rw-r--r--include/serialize.h9
-rw-r--r--modules/database/db_sql_live.cpp46
-rw-r--r--src/serialize.cpp3
4 files changed, 11 insertions, 50 deletions
diff --git a/include/modules.h b/include/modules.h
index 627bbab59..29da80cf3 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -927,7 +927,6 @@ class CoreExport Module : public Extensible
virtual void OnSerializeCheck(SerializeType *) { }
virtual void OnSerializableConstruct(Serializable *) { }
virtual void OnSerializableDestruct(Serializable *) { }
- virtual void OnSerializePtrAssign(Serializable *) { }
virtual void OnSerializableUpdate(Serializable *) { }
/** Called when a chanserv/set command is used
@@ -998,7 +997,7 @@ enum Implementation
I_OnChannelModeSet, I_OnChannelModeUnset, I_OnUserModeSet, I_OnUserModeUnset, I_OnChannelModeAdd, I_OnUserModeAdd,
I_OnMLock, I_OnUnMLock, I_OnServerSync, I_OnUplinkSync, I_OnBotPrivmsg, I_OnPrivmsg, I_OnLog,
- I_OnSerializeCheck, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializePtrAssign, I_OnSerializableUpdate,
+ I_OnSerializeCheck, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializableUpdate,
I_END
};
diff --git a/include/serialize.h b/include/serialize.h
index fd8e925ab..655501d47 100644
--- a/include/serialize.h
+++ b/include/serialize.h
@@ -254,10 +254,7 @@ class serialize_obj : public dynamic_reference_base
if (!this->invalid)
{
if (this->ref)
- {
- FOREACH_MOD(I_OnSerializePtrAssign, OnSerializePtrAssign(this->ref));
this->ref->QueueUpdate();
- }
return this->ref;
}
return NULL;
@@ -268,10 +265,7 @@ class serialize_obj : public dynamic_reference_base
if (!this->invalid)
{
if (this->ref)
- {
- FOREACH_MOD(I_OnSerializePtrAssign, OnSerializePtrAssign(this->ref));
this->ref->QueueUpdate();
- }
return this->ref;
}
return NULL;
@@ -282,10 +276,7 @@ class serialize_obj : public dynamic_reference_base
if (!this->invalid)
{
if (this->ref)
- {
- FOREACH_MOD(I_OnSerializePtrAssign, OnSerializePtrAssign(this->ref));
this->ref->QueueUpdate();
- }
return this->ref;
}
return NULL;
diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp
index 2aa3b73e6..9b683481b 100644
--- a/modules/database/db_sql_live.cpp
+++ b/modules/database/db_sql_live.cpp
@@ -74,7 +74,7 @@ class DBMySQL : public Module, public Pipe
this->ro = false;
this->init = false;
- Implementation i[] = { I_OnReload, I_OnShutdown, I_OnLoadDatabase, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializePtrAssign, I_OnSerializeCheck, I_OnSerializableUpdate };
+ Implementation i[] = { I_OnReload, I_OnShutdown, I_OnLoadDatabase, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializeCheck, I_OnSerializableUpdate };
ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
OnReload();
@@ -153,42 +153,6 @@ class DBMySQL : public Module, public Pipe
s_type->objects.erase(obj->id);
}
- void OnSerializePtrAssign(Serializable *obj) anope_override
- {
- SerializeType *stype = obj->GetSerializableType();
- if (stype == NULL || !this->CheckInit() || stype->GetTimestamp() == Anope::CurTime)
- return;
-
- if (obj->IsCached())
- return;
- obj->UpdateCache();
-
- SQLResult res = this->RunQueryResult("SELECT * FROM `" + this->prefix + stype->GetName() + "` WHERE `id` = " + stringify(obj->id));
-
- if (res.Rows() == 0)
- obj->destroy();
- else
- {
- const std::map<Anope::string, Anope::string> &row = res.Row(0);
-
- if (res.Get(0, "timestamp").empty())
- {
- obj->destroy();
- stype->objects.erase(obj->id);
- }
- else
- {
- Serialize::Data data;
-
- for (std::map<Anope::string, Anope::string>::const_iterator it = row.begin(), it_end = row.end(); it != it_end; ++it)
- data[it->first] << it->second;
-
- if (stype->Unserialize(obj, data) == NULL)
- obj->destroy();
- }
- }
- }
-
void OnSerializeCheck(SerializeType *obj) anope_override
{
if (!this->CheckInit() || obj->GetTimestamp() == Anope::CurTime)
@@ -241,8 +205,12 @@ class DBMySQL : public Module, public Pipe
Serializable *new_s = obj->Unserialize(s, data);
if (new_s)
{
- new_s->id = id;
- obj->objects[id] = new_s;
+ // If s == new_s then s->id == new_s->id
+ if (s != new_s)
+ {
+ new_s->id = id;
+ obj->objects[id] = new_s;
+ }
}
else
s->destroy();
diff --git a/src/serialize.cpp b/src/serialize.cpp
index 39d0cdd8f..45a43fb8e 100644
--- a/src/serialize.cpp
+++ b/src/serialize.cpp
@@ -122,6 +122,9 @@ void Serializable::destroy()
void Serializable::QueueUpdate()
{
+ /* Check for modifications now */
+ FOREACH_MOD(I_OnSerializeCheck, OnSerializeCheck(this->GetSerializableType()));
+ /* Schedule updater */
FOREACH_MOD(I_OnSerializableUpdate, OnSerializableUpdate(this));
}