Browse Source

Fix storing user groups in databases not working

Legacy(?) code that deallocated database instance before returning it
and allowing to use `MutableText` as a key for database.
develop
Anton Tarasenko 1 year ago
parent
commit
159f1dc5a1
  1. 25
      sources/Data/Database/DBAPI.uc

25
sources/Data/Database/DBAPI.uc

@ -250,48 +250,49 @@ public final function LocalDatabaseInstance LoadLocal(BaseText databaseName)
local DBRecord rootRecord; local DBRecord rootRecord;
local Text rootRecordName; local Text rootRecordName;
local LocalDatabase newConfig; local LocalDatabase newConfig;
local LocalDatabaseInstance newLocalDBInstance; local LocalDatabaseInstance newLocalDBInstance, result;
local Text dbKey; local Text dbKey;
if (databaseName == none) { if (databaseName == none) {
return none; return none;
} }
CreateLocalDBMapIfMissing(); CreateLocalDBMapIfMissing();
if (loadedLocalDatabases.HasKey(databaseName)) dbKey = databaseName.Copy();
if (loadedLocalDatabases.HasKey(dbKey))
{ {
return LocalDatabaseInstance(loadedLocalDatabases result = LocalDatabaseInstance(loadedLocalDatabases.GetItem(dbKey));
.GetItem(databaseName)); _.memory.Free(dbKey);
return result;
} }
// No need to check `databaseName` for being valid, // No need to check `dbKey` for being valid,
// since `Load()` will just return `none` if it is not. // since `Load()` will just return `none` if it is not.
newConfig = class'LocalDatabase'.static.Load(databaseName); newConfig = class'LocalDatabase'.static.Load(dbKey);
if (newConfig == none) { if (newConfig == none) {
_.memory.Free(dbKey);
return none; return none;
} }
if (!newConfig.HasDefinedRoot() && !newConfig.ShouldCreateIfMissing()) { if (!newConfig.HasDefinedRoot() && !newConfig.ShouldCreateIfMissing()) {
_.memory.Free(dbKey);
return none; return none;
} }
newLocalDBInstance = LocalDatabaseInstance(_.memory.Allocate(localDBClass)); newLocalDBInstance = LocalDatabaseInstance(_.memory.Allocate(localDBClass));
dbKey = databaseName.Copy();
loadedLocalDatabases.SetItem(dbKey, newLocalDBInstance); loadedLocalDatabases.SetItem(dbKey, newLocalDBInstance);
dbKey.FreeSelf(); dbKey.FreeSelf();
if (newConfig.HasDefinedRoot()) if (newConfig.HasDefinedRoot())
{ {
rootRecordName = newConfig.GetRootName(); rootRecordName = newConfig.GetRootName();
rootRecord = class'DBRecord'.static rootRecord = class'DBRecord'.static.LoadRecord(rootRecordName, dbKey);
.LoadRecord(rootRecordName, databaseName);
} }
else else
{ {
rootRecord = class'DBRecord'.static.NewRecord(databaseName); rootRecord = class'DBRecord'.static.NewRecord(dbKey);
rootRecordName = _.text.FromString(string(rootRecord.name)); rootRecordName = _.text.FromString(string(rootRecord.name));
newConfig.SetRootName(rootRecordName); newConfig.SetRootName(rootRecordName);
newConfig.Save(); newConfig.Save();
} }
newLocalDBInstance.Initialize(newConfig, rootRecord); newLocalDBInstance.Initialize(newConfig, rootRecord);
_.logger.Auto(infoLocalDatabaseLoaded).Arg(databaseName.Copy()); _.logger.Auto(infoLocalDatabaseLoaded).Arg(dbKey);
_.memory.Free(rootRecordName); _.memory.Free(rootRecordName);
_.memory.Free(newLocalDBInstance);
return newLocalDBInstance; return newLocalDBInstance;
} }

Loading…
Cancel
Save