非常慢的sqlite(SQLite-Net Extensions)

时间:2016-04-22 11:29:07

标签: c# sqlite windows-phone-8.1 sqlite-net sqlite-net-extensions

我在我的Windows手机8.1上使用SQLite-Net Extensions,因为我认为SD卡的速度超过了20行,所以插入了2000行。但是从数据库中选择似乎也很慢。按ID(int)选择所有(2000)行需要大约120秒。我打开数据库后立即尝试执行SQLITE PRAGMAS。它对选择的速度没有影响。

  dbConnection.ExecuteScalarAsync<int>("PRAGMA main.locking_mode = EXCLUSIVE").Wait();
        dbConnection.ExecuteScalarAsync<int>("PRAGMA main.synchronous = NORMAL").Wait();
        dbConnection.ExecuteScalarAsync<int>("PRAGMA main.journal_mode = WAL").Wait();
        dbConnection.ExecuteScalarAsync<int>("PRAGMA main.cache_size = 10000").Wait();
       dbConnection.ExecuteScalarAsync<int>("PRAGMA main.temp_store = MEMORY").Wait();

我正在使用SQLite Net扩展的异步版本: SQLite.Net.Async.SQLiteAsyncConnection

你能否通过正确和快速的方式给我一些如何使用SQLite-Net Extensions的sqlite的建议?

这是我从子文件夹中选择文件的递归方法的示例:

      private async Task<List<SongModel>> GetAllSongsFromFolderHelp(int folderID,bool fromSubFolders,bool appendChilderen ,List<SongModel> filesAcc)
    {
        List<DbFFModel> files = await dbConnection.QueryAsync<DbFFModel>("Select * from DbFFModel where IDParent = ?", folderID); //select
        foreach (DbFFModel ff in files)
        {
            if (ff.IsFile)
            {
                SongModel tmp = await this.GetSongByFileIDAsync(ff.ID, appendChilderen);
                if(tmp != null)
                    filesAcc.Add(tmp);
            }
            else if (fromSubFolders)
                await GetAllSongsFromFolderHelp(ff.ID, fromSubFolders,appendChilderen, filesAcc);
        }

        return filesAcc;
    }

这是插入记录的示例:

            IReadOnlyList<StorageFile> files = await storageFolder.GetFilesAsync();
        foreach (StorageFile storageFile in files)
        {
            bool isSupportedMusic = Classes.SupportedFiles.IsSupportedMusic(storageFile.ContentType, storageFile.FileType);
            if (isSupportedMusic)
            {
                BasicProperties fileProperties = await storageFile.GetBasicPropertiesAsync();
                int fileID = await dbConnection.ExecuteScalarAsync<int>("select ID from DbFFModel where Path = ?", storageFile.Path);
                DbFFModel dbFile = await dbConnection.FindAsync<DbFFModel>(fileID);

                bool updateFile = true;
                if (dbFile == null || (!DateTimeComparer.IsEqualRounded(dbFile.DateModified, Convert.ToDateTime(fileProperties.DateModified.ToString()))))
                {
                    if (dbFile == null)
                    {
                        updateFile = false;
                        dbFile = new DbFFModel();
                    }

                    dbFile.Mark = true;
                    dbFile.IDParent = dbFolder.ID;
                    dbFile.Path = storageFile.Path;
                    dbFile.IsFile = true;
                    dbFile.DisplayName = Path.GetFileName(storageFile.Path);
                    dbFile.DateCreated = storageFile.DateCreated.DateTime;
                    dbFile.DateModified = fileProperties.DateModified.DateTime;

                    if (updateFile) 
                        await dbConnection.UpdateAsync(dbFile);//update row
                    else
                        await dbConnection.InsertAsync(dbFile);//insert row

                    await MakeSongDb(dbFile.ID, storageFile);
                }
                else
                {
                    await UpdateMark(dbFile);
                }
            }
        }

由于

0 个答案:

没有答案