diff --git a/gaseous-server/Classes/Filters.cs b/gaseous-server/Classes/Filters.cs index 9e66c7e..cbc07e1 100644 --- a/gaseous-server/Classes/Filters.cs +++ b/gaseous-server/Classes/Filters.cs @@ -24,7 +24,7 @@ namespace gaseous_server.Classes ageRestriction_Generic += " OR view_Games.AgeGroupId IS NULL"; } - string sql = "SELECT DISTINCT Platform.Id, Platform.Abbreviation, Platform.AlternativeName, Platform.`Name`, Platform.PlatformLogo, (SELECT COUNT(*) AS GameCount FROM (SELECT DISTINCT Games_Roms.GameId AS ROMGameId, Games_Roms.PlatformId, view_Games.AgeGroupId FROM Games_Roms LEFT JOIN view_Games ON view_Games.Id = Games_Roms.GameId) Game WHERE Game.PlatformId = Platform.Id AND (" + ageRestriction_Platform + ")) AS GameCount FROM Platform LEFT JOIN Relation_Game_Platforms ON Relation_Game_Platforms.PlatformsId = Platform.Id LEFT JOIN view_Games ON view_Games.Id = Relation_Game_Platforms.GameId HAVING GameCount > 0 ORDER BY Platform.`Name`;"; + string sql = "SELECT Platform.Id, Platform.`Name`, COUNT(view_Games.Id) AS GameCount FROM view_Games JOIN Relation_Game_Platforms ON Relation_Game_Platforms.GameId = view_Games.Id AND (Relation_Game_Platforms.PlatformsId IN (SELECT DISTINCT PlatformId FROM Games_Roms WHERE Games_Roms.GameId = view_Games.Id)) JOIN Platform ON Platform.Id = Relation_Game_Platforms.PlatformsId WHERE (" + ageRestriction_Generic + ") GROUP BY Platform.`Name` ORDER BY Platform.`Name`;"; DataTable dbResponse = db.ExecuteCMD(sql); @@ -108,7 +108,7 @@ namespace gaseous_server.Classes private static DataTable GetGenericFilterItem(Database db, string Name, string AgeRestriction_Generic) { - string sql = "SELECT DISTINCT .Id, .`Name`, COUNT(view_Games.Id) AS GameCount FROM LEFT JOIN Relation_Game_s ON Relation_Game_s.sId = .Id LEFT JOIN view_Games ON view_Games.Id = Relation_Game_s.GameId WHERE (" + AgeRestriction_Generic + ") GROUP BY .Id ORDER BY .`Name`;"; + string sql = "SELECT DISTINCT .Id, .`Name`, COUNT(view_Games.Id) AS GameCount FROM LEFT JOIN Relation_Game_s ON Relation_Game_s.sId = .Id LEFT JOIN view_Games ON view_Games.Id = Relation_Game_s.GameId WHERE (" + AgeRestriction_Generic + ") GROUP BY .Id HAVING GameCount > 0 ORDER BY .`Name`;"; sql = sql.Replace("", Name); DataTable dbResponse = db.ExecuteCMD(sql); diff --git a/gaseous-server/Classes/ImportGames.cs b/gaseous-server/Classes/ImportGames.cs index 3abdcde..c643227 100644 --- a/gaseous-server/Classes/ImportGames.cs +++ b/gaseous-server/Classes/ImportGames.cs @@ -711,6 +711,7 @@ namespace gaseous_server.Classes StoreROM(library, hash, determinedGame, determinedPlatform, sig, LibraryFile); } } + StatusCount += 1; } ClearStatus(); diff --git a/gaseous-server/Classes/Logging.cs b/gaseous-server/Classes/Logging.cs index c6ccdc7..b72437b 100644 --- a/gaseous-server/Classes/Logging.cs +++ b/gaseous-server/Classes/Logging.cs @@ -275,8 +275,8 @@ namespace gaseous_server.Classes Process = (string)row["Process"], Message = (string)row["Message"], ExceptionValue = (string)row["Exception"], - CorrelationId = (string)row["CorrelationId"], - CallingProcess = (string)row["CallingProcess"] + CorrelationId = (string)Common.ReturnValueIfNull(row["CorrelationId"], ""), + CallingProcess = (string)Common.ReturnValueIfNull(row["CallingProcess"], "") }; logs.Add(log); diff --git a/gaseous-server/Classes/Metadata/Games.cs b/gaseous-server/Classes/Metadata/Games.cs index 0bfcd95..e687e86 100644 --- a/gaseous-server/Classes/Metadata/Games.cs +++ b/gaseous-server/Classes/Metadata/Games.cs @@ -293,8 +293,36 @@ namespace gaseous_server.Classes.Metadata var results = await comms.APIComm(IGDBClient.Endpoints.Games, fieldList, WhereClause); var result = results.First(); + // add artificial unknown platform mapping + List platformIds = new List(); + platformIds.Add(0); + if (result.Platforms != null) + { + if (result.Platforms.Ids != null) + { + platformIds.AddRange(result.Platforms.Ids.ToList()); + } + } + result.Platforms = new IdentitiesOrValues( + ids: platformIds.ToArray() + ); + return result; } + + public static void AssignAllGamesToPlatformIdZero() + { + Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); + string sql = "SELECT * FROM Game;"; + DataTable gamesTable = db.ExecuteCMD(sql); + foreach (DataRow gameRow in gamesTable.Rows) + { + sql = "DELETE FROM Relation_Game_Platforms WHERE PlatformsId = 0 AND GameId = @Id; INSERT INTO Relation_Game_Platforms (GameId, PlatformsId) VALUES (@Id, 0);"; + Dictionary dbDict = new Dictionary(); + dbDict.Add("Id", (long)gameRow["Id"]); + db.ExecuteCMD(sql, dbDict); + } + } public static Game[] SearchForGame(string SearchString, long PlatformId, SearchType searchType) { diff --git a/gaseous-server/Classes/Metadata/Platforms.cs b/gaseous-server/Classes/Metadata/Platforms.cs index 2b6f06d..331a872 100644 --- a/gaseous-server/Classes/Metadata/Platforms.cs +++ b/gaseous-server/Classes/Metadata/Platforms.cs @@ -168,6 +168,20 @@ namespace gaseous_server.Classes.Metadata return result; } + + public static void AssignAllPlatformsToGameIdZero() + { + Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); + string sql = "SELECT * FROM Platform;"; + DataTable platformsTable = db.ExecuteCMD(sql); + foreach (DataRow platformRow in platformsTable.Rows) + { + sql = "DELETE FROM Relation_Game_Platforms WHERE GameId = 0 AND PlatformsId = @Id; INSERT INTO Relation_Game_Platforms (GameId, PlatformsId) VALUES (0, @Id);"; + Dictionary dbDict = new Dictionary(); + dbDict.Add("Id", (long)platformRow["Id"]); + db.ExecuteCMD(sql, dbDict); + } + } } } diff --git a/gaseous-server/Classes/Metadata/Storage.cs b/gaseous-server/Classes/Metadata/Storage.cs index f593a17..6935fab 100644 --- a/gaseous-server/Classes/Metadata/Storage.cs +++ b/gaseous-server/Classes/Metadata/Storage.cs @@ -16,32 +16,14 @@ namespace gaseous_server.Classes.Metadata Expired } - //private static Dictionary ObjectCache = new Dictionary(); - public static CacheStatus GetCacheStatus(string Endpoint, string Slug) { - // CacheClean(); - // if (ObjectCache.ContainsKey(Endpoint + Slug)) - // { - // return CacheStatus.Current; - // } - // else - // { - return _GetCacheStatus(Endpoint, "slug", Slug); - // } + return _GetCacheStatus(Endpoint, "slug", Slug); } public static CacheStatus GetCacheStatus(string Endpoint, long Id) { - // CacheClean(); - // if (ObjectCache.ContainsKey(Endpoint + Id)) - // { - // return CacheStatus.Current; - // } - // else - // { - return _GetCacheStatus(Endpoint, "id", Id); - // } + return _GetCacheStatus(Endpoint, "id", Id); } public static CacheStatus GetCacheStatus(DataRow Row) @@ -185,21 +167,6 @@ namespace gaseous_server.Classes.Metadata { string Endpoint = EndpointType.GetType().Name; - // if (ObjectCache.ContainsKey(Endpoint + SearchValue)) - // { - // MemoryCacheObject cacheObject = ObjectCache[Endpoint + SearchValue]; - // if (cacheObject.ExpiryTime < DateTime.UtcNow) - // { - // // object has expired, remove it - // ObjectCache.Remove(Endpoint + SearchValue); - // } - // else - // { - // // object is valid, return it - // return (T)cacheObject.Object; - // } - // } - Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); string sql = "SELECT * FROM " + Endpoint + " WHERE " + SearchField + " = @" + SearchField; @@ -218,19 +185,7 @@ namespace gaseous_server.Classes.Metadata { DataRow dataRow = dt.Rows[0]; object returnObject = BuildCacheObject(EndpointType, dataRow); - // try { - // if (!ObjectCache.ContainsKey(Endpoint + SearchValue)) - // { - // ObjectCache.Add(Endpoint + SearchValue, new MemoryCacheObject{ - // Object = returnObject - // }); - // } - // } - // catch - // { - // // unable add item to cache - // ObjectCache.Clear(); - // } + return (T)returnObject; } } @@ -470,29 +425,6 @@ namespace gaseous_server.Classes.Metadata } } - // private static void CacheClean() - // { - // try - // { - // if (ObjectCache == null) - // { - // ObjectCache = new Dictionary(); - // } - // Dictionary workCache = ObjectCache; - // foreach (KeyValuePair objectCache in workCache) - // { - // if (objectCache.Value.ExpiryTime < DateTime.UtcNow) - // { - // ObjectCache.Remove(objectCache.Key); - // } - // } - // } - // catch - // { - // ObjectCache = new Dictionary(); - // } - // } - private class MemoryCacheObject { public object Object { get; set; } diff --git a/gaseous-server/Controllers/V1.1/GamesController.cs b/gaseous-server/Controllers/V1.1/GamesController.cs index 608c5db..c4c3a3a 100644 --- a/gaseous-server/Controllers/V1.1/GamesController.cs +++ b/gaseous-server/Controllers/V1.1/GamesController.cs @@ -265,7 +265,7 @@ namespace gaseous_server.Controllers.v1_1 if (model.Platform.Count > 0) { - tempVal = "Games_Roms.PlatformId IN ("; + tempVal = "Relation_Game_Platforms.PlatformsId IN ("; for (int i = 0; i < model.Platform.Count; i++) { if (i > 0) @@ -439,7 +439,7 @@ namespace gaseous_server.Controllers.v1_1 string orderByClause = "ORDER BY `" + orderByField + "` " + orderByOrder; Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString); - string sql = "SELECT DISTINCT view_Games.* FROM view_Games LEFT JOIN Games_Roms ON view_Games.Id = Games_Roms.GameId LEFT JOIN Relation_Game_Genres ON view_Games.Id = Relation_Game_Genres.GameId LEFT JOIN Relation_Game_GameModes ON view_Games.Id = Relation_Game_GameModes.GameId LEFT JOIN Relation_Game_PlayerPerspectives ON view_Games.Id = Relation_Game_PlayerPerspectives.GameId LEFT JOIN Relation_Game_Themes ON view_Games.Id = Relation_Game_Themes.GameId " + whereClause + " " + havingClause + " " + orderByClause; + string sql = "SELECT DISTINCT view_Games.* FROM view_Games LEFT JOIN Relation_Game_Platforms ON view_Games.Id = Relation_Game_Platforms.GameId AND (Relation_Game_Platforms.PlatformsId IN (SELECT DISTINCT PlatformId FROM Games_Roms WHERE Games_Roms.GameId = view_Games.Id)) LEFT JOIN Relation_Game_Genres ON view_Games.Id = Relation_Game_Genres.GameId LEFT JOIN Relation_Game_GameModes ON view_Games.Id = Relation_Game_GameModes.GameId LEFT JOIN Relation_Game_PlayerPerspectives ON view_Games.Id = Relation_Game_PlayerPerspectives.GameId LEFT JOIN Relation_Game_Themes ON view_Games.Id = Relation_Game_Themes.GameId " + whereClause + " " + havingClause + " " + orderByClause; List RetVal = new List(); diff --git a/gaseous-server/Models/PlatformMapping.cs b/gaseous-server/Models/PlatformMapping.cs index f4ff3b4..e513e8e 100644 --- a/gaseous-server/Models/PlatformMapping.cs +++ b/gaseous-server/Models/PlatformMapping.cs @@ -157,18 +157,18 @@ namespace gaseous_server.Models if (Update == false) { // insert - sql = "INSERT INTO PlatformMap (Id, RetroPieDirectoryName, WebEmulator_Type, WebEmulator_Core, AvailableWebEmulators) VALUES (@Id, @RetroPieDirectoryName, @WebEmulator_Type, @WebEmulator_Core, @AvailableWebEmulators)"; + sql = "INSERT INTO PlatformMap (Id, RetroPieDirectoryName, WebEmulator_Type, WebEmulator_Core, AvailableWebEmulators) VALUES (@Id, @RetroPieDirectoryName, @WebEmulator_Type, @WebEmulator_Core, @AvailableWebEmulators);"; } else { // update if (AllowAvailableEmulatorOverwrite == true) { - sql = "UPDATE PlatformMap SET RetroPieDirectoryName=@RetroPieDirectoryName, WebEmulator_Type=@WebEmulator_Type, WebEmulator_Core=@WebEmulator_Core, AvailableWebEmulators=@AvailableWebEmulators WHERE Id = @Id"; + sql = "UPDATE PlatformMap SET RetroPieDirectoryName=@RetroPieDirectoryName, WebEmulator_Type=@WebEmulator_Type, WebEmulator_Core=@WebEmulator_Core, AvailableWebEmulators=@AvailableWebEmulators WHERE Id = @Id; "; } else { - sql = "UPDATE PlatformMap SET RetroPieDirectoryName=@RetroPieDirectoryName, WebEmulator_Type=@WebEmulator_Type, WebEmulator_Core=@WebEmulator_Core WHERE Id = @Id"; + sql = "UPDATE PlatformMap SET RetroPieDirectoryName=@RetroPieDirectoryName, WebEmulator_Type=@WebEmulator_Type, WebEmulator_Core=@WebEmulator_Core WHERE Id = @Id;"; } } dbDict.Add("Id", item.IGDBId); diff --git a/gaseous-server/Program.cs b/gaseous-server/Program.cs index 0d876aa..531c983 100644 --- a/gaseous-server/Program.cs +++ b/gaseous-server/Program.cs @@ -393,7 +393,9 @@ Config.LibraryConfiguration.InitLibrary(); // insert unknown platform and game if not present gaseous_server.Classes.Metadata.Games.GetGame(0, false, false, false); +gaseous_server.Classes.Metadata.Games.AssignAllGamesToPlatformIdZero(); gaseous_server.Classes.Metadata.Platforms.GetPlatform(0); +gaseous_server.Classes.Metadata.Platforms.AssignAllPlatformsToGameIdZero(); // extract platform map if not present PlatformMapping.ExtractPlatformMap(); diff --git a/gaseous-server/Support/Database/MySQL/gaseous-1009.sql b/gaseous-server/Support/Database/MySQL/gaseous-1009.sql new file mode 100644 index 0000000..8971a4c --- /dev/null +++ b/gaseous-server/Support/Database/MySQL/gaseous-1009.sql @@ -0,0 +1,4 @@ +ALTER TABLE `Games_Roms` +ADD INDEX `id_LibraryId` (`LibraryId` ASC) VISIBLE, +ADD INDEX `id_MD5` USING BTREE (`MD5`) VISIBLE; + diff --git a/gaseous-server/gaseous-server.csproj b/gaseous-server/gaseous-server.csproj index d54f3a4..869bf0c 100644 --- a/gaseous-server/gaseous-server.csproj +++ b/gaseous-server/gaseous-server.csproj @@ -49,6 +49,7 @@ + @@ -180,5 +181,6 @@ +