Accelerate master data loading

This is on iOS.

I have a base database with about 350,000 objects. Objects (Product) have two properties: "Barcode" and "Designation". The user can search for an object by searching for "Barcode", and "Designation" must be returned. Everything is working fine, except for the slow ones. The code I'm using is:

    NSEntityDescription *_product = [NSEntityDescription entityForName:@"Product" inManagedObjectContext:importContext];
NSFetchRequest *fetch = [[NSFetchRequest alloc]init];

[fetch setEntity:_product];
[fetch setPredicate:[NSPredicate predicateWithFormat:@"Barcode == %@",theBarcode]];

 NSError *error = nil;
 NSArray *results = [importContext executeFetchRequest:fetch error:&error];

NSManagedObject *object = [results objectAtIndex:0];

Since I only want to get one object, is there a way to speed it up?

If I load each object into an array at startup, I get a very slow startup for the application and consuming a lot of RAM.

Thanks in advance!

EDIT: I added [fetch setFetchLimit: 1]; that speed it up a bit. But the speed slows down the further the object is in the database.

+3
3

Barcode ?

+7

, @paulbailey, , Barcode.

, (- ), - , CoreData .

CoreData - , , , .

, CoreData sqLite . Objective-C , FMDB , . .

CoreData, , Apple. , .

+4

, , , , Core Data , , searchitem, , .

There are many search algorithms that you can use depending on your database (sorted / unsorted lists, tree structure, etc.), you can use Quicksearch, Hashsearches, treeearch, etc.

Instead, you might consider setting up an SQlite database, which has some nice framework with smart search algorithms.

0
source

Source: https://habr.com/ru/post/1780012/


All Articles