Im inserting a huge amount of data into my sqlite database. Now it takes a long time to complete the process which would be frustuating for the user. Could anyone here give me any idea on how to make this process fast or any alternative.
我将大量数据插入我的sqlite数据库。现在,完成该过程需要很长时间,这对用户来说是令人沮丧的。这里的任何人都可以告诉我如何快速或任何替代方案。
Plss help me..
Plss帮帮我..
2 个解决方案
#1
1
-
If you're storing images or things like that, consider not storing that in the database, as it's pretty inefficient to do so. Store that sort of binary data in the Documents folder and if you need to keep track of it in the database, do so by storing the filenames in the database, but not the image.
如果您要存储图像或类似的东西,请考虑不将其存储在数据库中,因为这样做效率很低。将这种二进制数据存储在Documents文件夹中,如果需要在数据库中跟踪它,可以通过将文件名存储在数据库中而不是图像来实现。
-
If at all possible, do these operations in the background, such as through Grand Central Dispatch or
NSOperationQueue
. These technologies are also discussed in the Concurrency Programming Guide. If you're doing this with a SQLite wrapper, such as the excellent FMDB (which I heartily recommend you investigate if you haven't already), you can use itsFMDatabaseQueue
(which uses GCD) to coordinate background database operations with foreground database queries. Because it's using queues, you'll just want to make sure to break the background database operations in smaller tasks if possible to avoid the perception of blocking foreground database operations.如果可能的话,在后台执行这些操作,例如通过Grand Central Dispatch或NSOperationQueue。 “并发编程指南”中也讨论了这些技术。如果您使用SQLite包装器执行此操作,例如优秀的FMDB(我衷心建议您进行调查,如果您还没有),则可以使用其FMDatabaseQueue(使用GCD)来协调后台数据库操作与前台数据库查询。因为它使用队列,所以你只需要确保在较小的任务中打破后台数据库操作,以避免阻塞前台数据库操作的感觉。
#2
0
NSOperationQueue
provide the threads used to run their operations.
NSOperationQueue提供用于运行其操作的线程。
Create NSInvocationOperation
objects and add it in the array of NSOperationQueue
.
创建NSInvocationOperation对象并将其添加到NSOperationQueue数组中。
NSInvocationOperation *insertOperationObject1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(insertMethod1) object:nil];
NSInvocationOperation *insertOperationObject2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(insertMethod2) object:nil];
NSInvocationOperation *insertOperationObject3 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(insertMethod3) object:nil];
//adding database fetch operations to an NSOperationQueue
//将数据库获取操作添加到NSOperationQueue
NSOperationQueue *m_opqInsertQueue = [[[NSOperationQueue alloc] init] autorelease];
[m_opqCustomerProfileDataFetchQueue setMaxConcurrentOperationCount:1];
[m_opqCustomerProfileDataFetchQueue addOperations:[NSArray arrayWithObjects:insertOperationObject1, insertOperationObject2, insertOperationObject3, nil] waitUntilFinished:NO];
#1
1
-
If you're storing images or things like that, consider not storing that in the database, as it's pretty inefficient to do so. Store that sort of binary data in the Documents folder and if you need to keep track of it in the database, do so by storing the filenames in the database, but not the image.
如果您要存储图像或类似的东西,请考虑不将其存储在数据库中,因为这样做效率很低。将这种二进制数据存储在Documents文件夹中,如果需要在数据库中跟踪它,可以通过将文件名存储在数据库中而不是图像来实现。
-
If at all possible, do these operations in the background, such as through Grand Central Dispatch or
NSOperationQueue
. These technologies are also discussed in the Concurrency Programming Guide. If you're doing this with a SQLite wrapper, such as the excellent FMDB (which I heartily recommend you investigate if you haven't already), you can use itsFMDatabaseQueue
(which uses GCD) to coordinate background database operations with foreground database queries. Because it's using queues, you'll just want to make sure to break the background database operations in smaller tasks if possible to avoid the perception of blocking foreground database operations.如果可能的话,在后台执行这些操作,例如通过Grand Central Dispatch或NSOperationQueue。 “并发编程指南”中也讨论了这些技术。如果您使用SQLite包装器执行此操作,例如优秀的FMDB(我衷心建议您进行调查,如果您还没有),则可以使用其FMDatabaseQueue(使用GCD)来协调后台数据库操作与前台数据库查询。因为它使用队列,所以你只需要确保在较小的任务中打破后台数据库操作,以避免阻塞前台数据库操作的感觉。
#2
0
NSOperationQueue
provide the threads used to run their operations.
NSOperationQueue提供用于运行其操作的线程。
Create NSInvocationOperation
objects and add it in the array of NSOperationQueue
.
创建NSInvocationOperation对象并将其添加到NSOperationQueue数组中。
NSInvocationOperation *insertOperationObject1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(insertMethod1) object:nil];
NSInvocationOperation *insertOperationObject2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(insertMethod2) object:nil];
NSInvocationOperation *insertOperationObject3 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(insertMethod3) object:nil];
//adding database fetch operations to an NSOperationQueue
//将数据库获取操作添加到NSOperationQueue
NSOperationQueue *m_opqInsertQueue = [[[NSOperationQueue alloc] init] autorelease];
[m_opqCustomerProfileDataFetchQueue setMaxConcurrentOperationCount:1];
[m_opqCustomerProfileDataFetchQueue addOperations:[NSArray arrayWithObjects:insertOperationObject1, insertOperationObject2, insertOperationObject3, nil] waitUntilFinished:NO];