mirror of
https://github.com/anope/anope.git
synced 2026-07-08 15:23:12 +02:00
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
This commit is contained in:
+1
-2
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user