Windows Phone 8.1 で SQLite-Net 拡張機能を使用しています。SD カートの速度が原因で、2000 行の挿入に 20 分以上かかりました。しかし、データベースからの選択も非常に遅いようです。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);
}
}
}
ありがとう