Exemplo n.º 1
0
 /// <summary>
 /// Used for inserting beatmaps/invoking a large number of (no result)queries at once instead of one-by-one with is way slower.
 /// </summary>
 public void StartMassStoring()
 {
     lock (_sqlConnector)
     {
         string sql    = "SELECT Md5, MapId FROM (SELECT Md5, MapId FROM `withID` UNION SELECT Md5, MapId FROM `withoutID`)";
         var    reader = _sqlConnector.Query(sql);
         _md5List = new Dictionary <string, int>();
         while (reader.Read())
         {
             var hash  = reader.GetString(0);
             var mapId = reader.GetInt32(1);
             if (_md5List.ContainsKey(hash))
             {
                 //On collision delete both entrys.
                 _sqlConnector.RemoveBeatmap(hash);
             }
             else
             {
                 _md5List.Add(hash, mapId);
             }
         }
         reader.Dispose();
         _sqlConnector.StartMassStoring();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Used for inserting beatmaps/invoking a large number of (no result)queries at once instead of one-by-one with is way slower.
 /// </summary>
 public void StartMassStoring()
 {
     lock (_sqlConnector)
     {
         string sql    = "SELECT Md5 FROM (SELECT Md5 FROM `withID` UNION SELECT Md5 FROM `withoutID`)";
         var    reader = _sqlConnector.Query(sql);
         _md5List = new HashSet <string>();
         while (reader.Read())
         {
             _md5List.Add(reader.GetString(0));
         }
         reader.Dispose();
         _sqlConnector.StartMassStoring();
     }
 }
        /// <summary>
        /// Used for inserting beatmaps/invoking a large number of (no result)queries at once instead of one-by-one with is way slower.
        /// </summary>
        public void StartMassStoring()
        {
            if (_sqlConnector.MassInsertIsActive)
            {
                return;
            }
            lock (_sqlConnector)
            {
                string           sql = "SELECT Md5, MapId FROM (SELECT Md5, MapId FROM `withID` UNION SELECT Md5, MapId FROM `withoutID`)";
                SQLiteDataReader reader;
                try
                {
                    reader = _sqlConnector.Query(sql);
                }
                catch (SQLiteException e)
                {
                    if (e.ResultCode == SQLiteErrorCode.Corrupt)
                    {
                        _sqlConnector.ResetDatabase();
                        StartMassStoring();
                        return;
                    }

                    throw;
                }

                _beatmapChecksums = new Dictionary <string, MapIdFoundPair>();
                while (reader.Read())
                {
                    var hash  = reader.GetString(0);
                    var mapId = reader.GetInt32(1);
                    if (!_beatmapChecksums.ContainsKey(hash))
                    {
                        _beatmapChecksums.Add(hash, new MapIdFoundPair(mapId));
                    }
                }
                reader.Dispose();
                _sqlConnector.StartMassStoring();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Used for inserting beatmaps/invoking a large number of (no result)queries at once instead of one-by-one with is way slower.
        /// </summary>
        public void StartMassStoring()
        {
            if (_sqlConnector.MassInsertIsActive)
            {
                return;
            }
            lock (_sqlConnector)
            {
                string           sql = "SELECT Md5, MapId, BeatmapChecksum FROM (SELECT Md5, MapId, BeatmapChecksum FROM `withID` UNION SELECT Md5, MapId, BeatmapChecksum FROM `withoutID`)";
                SQLiteDataReader reader;
                try
                {
                    reader = _sqlConnector.Query(sql);
                }
                catch (SQLiteException e)
                {
                    if (e.ResultCode == SQLiteErrorCode.Corrupt)
                    {
                        _sqlConnector.ResetDatabase();
                        StartMassStoring();
                        return;
                    }

                    throw;
                }

                _beatmapChecksums = new Dictionary <string, MapIdMd5Pair>();
                while (reader.Read())
                {
                    var hash     = reader.GetString(0);
                    var mapId    = reader.GetInt32(1);
                    var checksum = reader.GetString(2);
                    if (_beatmapChecksums.ContainsKey(checksum))
                    {
                        //REALLY..? I don't think so.
                        var map1         = _sqlConnector.GetBeatmap(hash);
                        var map2         = _sqlConnector.GetBeatmap(_beatmapChecksums[checksum].Md5);
                        var map1Checksum = map1.GetChecksum();
                        var map2Checksum = map2.GetChecksum();
                        if (map1Checksum == map2Checksum)
                        {
                            //:( fair enough
                            var ex = new SQLiteException(SQLiteErrorCode.Constraint, "uh, oh... beatmap checksum collision");
                            ex.Data.Add("mapId1", map1.MapId);
                            ex.Data.Add("hash1", map1.Md5);
                            ex.Data.Add("mapId2", map2.MapId);
                            ex.Data.Add("hash2", map2.Md5);
                            ex.Data.Add("checksum", map1Checksum);
                            throw ex;
                        }

                        _beatmapChecksums.Remove(map1Checksum);
                        _beatmapChecksums.Remove(map2Checksum);

                        _beatmapChecksums.Add(map1Checksum, new MapIdMd5Pair(map1.MapId, map1.Md5));
                        _beatmapChecksums.Add(map2Checksum, new MapIdMd5Pair(map2.MapId, map2.Md5));
                    }
                    else
                    {
                        _beatmapChecksums.Add(checksum, new MapIdMd5Pair(mapId, hash));
                    }
                }
                reader.Dispose();
                _sqlConnector.StartMassStoring();
            }
        }