【发布时间】:2011-05-03 21:56:05
【问题描述】:
我正在访问近 30,000 个单词并显示在一个表格中。单词在 sqlite 文件中。因此,运行查询并将单词加载到表中需要很长时间(15 秒)。显然应用程序在启动时会等待 15 秒。
我怎样才能解决这个问题?
NSLog(@"Query start");
CFTimeInterval startTime = CFAbsoluteTimeGetCurrent();
FMResultSet *rs = [db executeQuery:@"select * from words order by no ASC "];
while ([rs next]) {
Word *word = [[Word alloc] initWithID:[rs intForColumn:@"id"]
no:[rs stringForColumn:@"no"]
en:[rs stringForColumn:@"en"]];
[words addObject: word];
}
[rs close];
[db close];
CFTimeInterval endTime = CFAbsoluteTimeGetCurrent();
float deltaTimeInSeconds = endTime - startTime;
NSLog(@"Time spent for query: %f seconds", deltaTimeInSeconds);
注意:原始表未排序。它是字典的单词列表,因此在显示时,必须在表格视图中按字母顺序排序。这就是为什么,我需要加载所有的单词。后台线程可能是一个更好的主意,从 sqlite 获取数据时填充数据。 sqlite 支持这个吗?使用回调方法获取数据。例如在 sqlite 查询中,对于获取的每 1000 条记录,我将更新我的表。我不太清楚该怎么做,如果你知道请给我一些提示。
【问题讨论】:
-
我不这么认为。这是一个 SQLite 单词表,用于在 Java 中创建的字典(数据输入在桌面完成)。
-
索引提高了性能。但并不多。它将加载时间从 15 秒降低到 6/7 秒。