refactor: performance improvements in signature import
This commit is contained in:
@@ -15,6 +15,10 @@ namespace gaseous_server.SignatureIngestors.TOSEC
|
||||
// connect to database
|
||||
Database db = new gaseous_tools.Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||
|
||||
List<Dictionary<string, object>> ImportedPlatforms = new List<Dictionary<string, object>>();
|
||||
List<Dictionary<string, object>> ImportedPublishers = new List<Dictionary<string, object>>();
|
||||
List<Dictionary<string, object>> ImportedGames = new List<Dictionary<string, object>>();
|
||||
|
||||
// process provided files
|
||||
Logging.Log(Logging.LogType.Information, "Signature Ingestor - TOSEC", "Importing from " + SearchPath);
|
||||
if (Directory.Exists(Config.LibraryConfiguration.LibrarySignatureImportDirectory_TOSEC))
|
||||
@@ -100,6 +104,21 @@ namespace gaseous_server.SignatureIngestors.TOSEC
|
||||
// store platform
|
||||
int gameSystem = 0;
|
||||
if (gameObject.System != null)
|
||||
{
|
||||
bool foundPlatform = false;
|
||||
string platformName = (string)dbDict["platform"];
|
||||
foreach (Dictionary<string, object> ImportedPlatform in ImportedPlatforms)
|
||||
{
|
||||
string importedPlatformName = (string)ImportedPlatform["Name"];
|
||||
if (importedPlatformName == platformName)
|
||||
{
|
||||
foundPlatform = true;
|
||||
gameSystem = (int)ImportedPlatform["Id"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundPlatform == false)
|
||||
{
|
||||
sql = "SELECT Id FROM Signatures_Platforms WHERE Platform=@platform";
|
||||
|
||||
@@ -116,12 +135,33 @@ namespace gaseous_server.SignatureIngestors.TOSEC
|
||||
{
|
||||
gameSystem = (int)sigDB.Rows[0][0];
|
||||
}
|
||||
|
||||
Dictionary<string, object> platformDetails = new Dictionary<string, object>();
|
||||
platformDetails.Add("Id", gameSystem);
|
||||
platformDetails.Add("Name", dbDict["platform"]);
|
||||
ImportedPlatforms.Add(platformDetails);
|
||||
}
|
||||
}
|
||||
dbDict.Add("systemid", gameSystem);
|
||||
|
||||
// store publisher
|
||||
int gamePublisher = 0;
|
||||
if (gameObject.Publisher != null)
|
||||
{
|
||||
bool foundPublisher = false;
|
||||
string publisherName = (string)dbDict["publisher"];
|
||||
foreach (Dictionary<string, object> ImportedPublisher in ImportedPublishers)
|
||||
{
|
||||
string importedPublisherName = (string)ImportedPublisher["Name"];
|
||||
if (importedPublisherName == publisherName)
|
||||
{
|
||||
foundPublisher = true;
|
||||
gamePublisher = (int)ImportedPublisher["Id"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundPublisher == false)
|
||||
{
|
||||
sql = "SELECT * FROM Signatures_Publishers WHERE Publisher=@publisher";
|
||||
|
||||
@@ -137,11 +177,35 @@ namespace gaseous_server.SignatureIngestors.TOSEC
|
||||
{
|
||||
gamePublisher = (int)sigDB.Rows[0][0];
|
||||
}
|
||||
|
||||
Dictionary<string, object> publisherDetails = new Dictionary<string, object>();
|
||||
publisherDetails.Add("Id", gamePublisher);
|
||||
publisherDetails.Add("Name", dbDict["publisher"]);
|
||||
ImportedPublishers.Add(publisherDetails);
|
||||
}
|
||||
}
|
||||
dbDict.Add("publisherid", gamePublisher);
|
||||
|
||||
// store game
|
||||
int gameId = 0;
|
||||
bool foundGame = false;
|
||||
foreach (Dictionary<string, object> ImportedGame in ImportedGames)
|
||||
{
|
||||
if (((string)ImportedGame["Name"] == (string)dbDict["name"]) &&
|
||||
((string)ImportedGame["Year"] == (string)dbDict["year"]) &&
|
||||
((int)ImportedGame["PublisherId"] == (int)dbDict["publisherid"]) &&
|
||||
((int)ImportedGame["SystemId"] == (int)dbDict["systemid"]) &&
|
||||
((string)ImportedGame["Country"] == (string)dbDict["country"]) &&
|
||||
((string)ImportedGame["Language"] == (string)dbDict["language"]))
|
||||
{
|
||||
foundGame = true;
|
||||
gameId = (int)ImportedGame["Id"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundGame == false)
|
||||
{
|
||||
sql = "SELECT * FROM Signatures_Games WHERE Name=@name AND Year=@year AND Publisherid=@publisher AND Systemid=@systemid AND Country=@country AND Language=@language";
|
||||
|
||||
sigDB = db.ExecuteCMD(sql, dbDict);
|
||||
@@ -160,6 +224,17 @@ namespace gaseous_server.SignatureIngestors.TOSEC
|
||||
gameId = (int)sigDB.Rows[0][0];
|
||||
}
|
||||
|
||||
Dictionary<string, object> gameDetails = new Dictionary<string, object>();
|
||||
gameDetails.Add("Id", gameId);
|
||||
gameDetails.Add("Name", dbDict["name"]);
|
||||
gameDetails.Add("Year", dbDict["year"]);
|
||||
gameDetails.Add("PublisherId", dbDict["publisherid"]);
|
||||
gameDetails.Add("SystemId", dbDict["systemid"]);
|
||||
gameDetails.Add("Country", dbDict["country"]);
|
||||
gameDetails.Add("Language", dbDict["language"]);
|
||||
ImportedGames.Add(gameDetails);
|
||||
}
|
||||
|
||||
// store rom
|
||||
foreach (RomSignatureObject.Game.Rom romObject in gameObject.Roms)
|
||||
{
|
||||
|
Reference in New Issue
Block a user