1

sqlite と fmdb ラッパーを使用して、iphone 用のデータベースを作成しました。

データベースには約 3500 行あります。これには 14 列あります。ID 用に 1 つ、名前/主な検索用語用に 1 つ、代替検索用語用に 9 つの他の列、短い説明用に他の 3 つの列があります。

私のアプリの最初のビューは、Google に少し似た検索バーを表示する導入画面です。検索バーを実装すると、目的の結果を含むテーブルを含む別のビューが表示されます。ビュー間のこの最初の遷移には 1 ~ 2 秒の遅延があります。さらに、テーブルではシームレスなスクロールが許可されていません。最後に、表のセルを選択すると、シームレスに最終ビューに移動しますが、表ビューに戻ろうとすると、さらに 1 ~ 2 秒の遅延が発生します。

3500 行で 5 列しかない小さなデータベースでこのアプリを実行しました。この場合、9 つの代替検索語がデータベースから削除されます。iPhone でこのようなアプリを実行すると、かなり効率的です... わずかな遅延がありますが、実際には目立ちません... おそらく遅延に気付きませんでした (ただ私が使用している大規模なデータベースではそれほど明らかではなかった場合は、小さな遅延は正常であると想定しています。

私は sqlite データベースを微調整する必要があるという結論に達したので、主な質問が 2 つあります。

  1. sqlite dbのプラグマ設定(同期、ジャーナルモード、キャッシュサイズなど)を変更すると効率が向上することを読みました。これらの設定を mozilla プラグインで変更すると、保存されないようです... プラグインを開いて閉じると、設定が古いデフォルトに戻ります。これらを xcode 経由で設定できることがわかりました...これらの設定を FMDB ラッパーのどこで設定するのか疑問に思っていますか?
  2. インデックスを作成すると速度が大幅に向上すると聞いたことがあります。何をインデックス化すればよいかよくわかりませんが、インデックス化する場合、FMDB ラッパーのコーディングを変更する必要がありますか? さらに、データベース内のすべてのデータを使用したいという理想的な状況を考慮して、インデックスを作成する必要があるのは何ですか?

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    Data *data = [[[DataController instance]filterDataWithName:searchString:searchString:searchString:searchString:searchString:searchString:searchString:searchString:searchString:searchString]objectAtIndex:indexPath.row];

    cell.textLabel.text = data.aDataName;
    cell.detailTextLabel.text = data.aDataStatus; 

    // Configure the cell.
    return cell;
}

-(NSMutableArray*)filterDataWithName:(NSString*)aDataName:(NSString*)altSearchTermA:(NSString*)altSearchTermB:(NSString*)altSearchTermC:(NSString*)altSearchTermD:(NSString*)altSearchTermE:(NSString*)altSearchTermF:(NSString*)altSearchTermG:(NSString*)altSearchTermH:(NSString*)altSearchTermI;

 {

    if ((aDataName && [aDataName length] > 0) && (altSearchTermA && [altSearchTermA length] > 0) && (altSearchTermB && [altSearchTermB length] > 0) && (altSearchTermC && [altSearchTermC length] > 0) && (altSearchTermD && [altSearchTermD length] > 0) && (altSearchTermE && [altSearchTermE length] > 0) && (altSearchTermF && [altSearchTermF length] > 0) && (altSearchTermG && [altSearchTermG length] > 0) && (altSearchTermH && [altSearchTermH length] > 0) && (altSearchTermI && [altSearchTermI length] > 0))
    {
        NSMutableArray *filterDataArray = [[NSMutableArray alloc]initWithArray:dataList];

        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(aDataName CONTAINS[cd] %@) OR (altSearchTermA CONTAINS[cd] %@) OR (altSearchTermB CONTAINS[cd] %@) OR (altSearchTermC CONTAINS[cd] %@) OR (altSearchTermD CONTAINS[cd] %@) OR (altSearchTermE CONTAINS[cd] %@) OR (altSearchTermF CONTAINS[cd] %@) OR (altSearchTermG CONTAINS[cd] %@) OR (altSearchTermH CONTAINS[cd] %@) OR (altSearchTermI CONTAINS[cd] %@)", aDataName, altSearchTermA,altSearchTermB,altSearchTermC,altSearchTermD,altSearchTermE,altSearchTermF,altSearchTermG,altSearchTermH,altSearchTermI];

        [filterDataArray filterUsingPredicate:predicate];
        return filterDataArray;
    }
    else
    {
        return dataList;
    }

    }
4

2 に答える 2

1

cellForRowAtIndexPathは、作成されたセルごとに呼び出されるため、filterDataWithName関数はすべてのセル/行に対して呼び出されます。

filterDataWithNameを別の場所で呼び出し、cellForRowAtIndexPathのNSMutableArrayを次のように使用します。

cell.textLabel.text = [[filterDataArray objectAtIndex:indexpath.row] data.aDataName];

于 2012-02-01T15:55:16.493 に答える
0

わかりました - ダレンが述べたように、上記の問題を見逃しました - これで解決しない場合 ..... テーブルで徹底的な検索を実行する必要がある同様の問題に遭遇しました。このようなものを使用して、クエリを 1 行に制限してみてください。

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Level2CustomCell *cell = (Level2CustomCell*) [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
    if (cell == nil)
    {
        cell = [[[Level2CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    // SEARCH ENGINE TIME
    NSString *likeTitle = [NSString stringWithFormat:@" TITLE LIKE '%@%@%@'",@"%",msgView.searchBar.text,@"%"];
    NSString *likeSearch = [NSString stringWithFormat:@" SORT4='%@' AND SEARCH LIKE '%@%@%@'",selectedSection,@"%",msgView.searchBar.text,@"%"];
    NSString *likeAddress = [NSString stringWithFormat:@" SORT4='%@' AND ADDRESS LIKE '%@%@%@'",selectedSection,@"%",msgView.searchBar.text,@"%"];
    NSString *likeContent = [NSString stringWithFormat:@" SORT4='%@' AND CONTENT LIKE '%@%@%@'",selectedSection,@"%",msgView.searchBar.text,@"%"];


    qry = [NSString stringWithFormat: @"select * from SPOT_INFO WHERE SORT4 = '%@' AND %@ OR %@ OR %@ OR %@ order by TITLE limit 1 offset %d",selectedSection,likeTitle,likeSearch,likeAddress,likeContent,[indexPath row]];


    DLog(@"qry :%@",qry);

    FMResultSet *rs =   [appDelegate.userdb executeQuery:qry];

    if ([rs next]) {
        NSString *title = [rs stringForColumn:@"TITLE"];
        DLog(@"title %@",title);
        NSString *content = [rs stringForColumn:@"CONTENT"];
        NSString *imgFileName = [rs stringForColumn:@"IMG_NAME"];

    }
    [rs close];

}

非ブロッキング gcd (グランド セントラル ディスパッチ) コードを持つ egodatabase をお勧めします https://github.com/jdp-global/egodatabase

于 2012-03-13T09:00:18.580 に答える