sangony
sangony

Reputation: 11696

App structure for storing large quantity of records

I am creating an iOS app that deals with real estate listings. The current structure is as follows:

  1. Device contacts server and downloads an index file which contains all current record IDs on the server and the last time each record was modified.

  2. Each core data record on the device is checked against the index file and either: a) the record is up to date and nothing happens. b) the record is out of date, is deleted from the device and reloaded from the server. c) the record is not part of the index file and is deleted from the device. d) no record is found on the device with the listing ID and is downloaded from the server.

I use an index file because I have to download only a small part of the data for each record in order to compare.

My problem is this, I currently have about 1250 test records on the server. With the current setup it is taking almost 3 minutes (using WiFi) to complete the initial index check routines. There has to be a better way to handle a large number of records in a iOS app. Am I wrong for trying to load all the records in core data up front?

For reference I am including the ListingRecord.h

@property (nonatomic, retain) NSString * amenitiesText;
@property (nonatomic, retain) NSString * bodyLabel1;
@property (nonatomic, retain) NSString * bodyLabel2;
@property (nonatomic, retain) NSString * bodyLabel3;
@property (nonatomic, retain) NSString * brokerID;
@property (nonatomic, retain) NSString * companyID;
@property (nonatomic, retain) NSDate * dateCreated;
@property (nonatomic, retain) NSString * descriptionText;
@property (nonatomic, retain) NSString * displayPrice;
@property (nonatomic, retain) NSString * featuredListing;
@property (nonatomic, retain) NSString * headerLabel;
@property (nonatomic, retain) NSData * headerPhoto;
@property (nonatomic, retain) NSString * lastUpdate;
@property (nonatomic, retain) NSNumber * latitudeData;
@property (nonatomic, retain) NSNumber * listingID;
@property (nonatomic, retain) NSString * listingType1;
@property (nonatomic, retain) NSString * listingType2;
@property (nonatomic, retain) NSString * listingType3;
@property (nonatomic, retain) NSString * listingType4;
@property (nonatomic, retain) NSString * listingType5;
@property (nonatomic, retain) NSString * listingType6;
@property (nonatomic, retain) NSString * listingType7;
@property (nonatomic, retain) NSString * listingType8;
@property (nonatomic, retain) NSNumber * longitudeData;
@property (nonatomic, retain) NSNumber * numberPrice;
@property (nonatomic, retain) NSData * photo1;
@property (nonatomic, retain) NSData * photo2;
@property (nonatomic, retain) NSData * photo3;
@property (nonatomic, retain) NSData * photo4;
@property (nonatomic, retain) NSData * photo5;
@property (nonatomic, retain) NSString * pinLabel;
@property (nonatomic, retain) NSData * thumbnailPic;
@property (nonatomic, retain) NSString * sessionID;

The index file contains the listingID and the lastUpdate and compares those against the core data records on the device.

Upvotes: 1

Views: 104

Answers (2)

user523234
user523234

Reputation: 14834

If you need to do all this at once, I would arrange your flow logic so that you can do this "initial index check routines" in the background thread.

Another option would be sending the index file to the server and let your backend server do the work and it returns only the lists for adding, deleting, updating, etc. This would depend on if your backend server is capable of doing this.

Upvotes: 2

Benny
Benny

Reputation: 5092

It seems like there are two bottle necks, the communication with the server and the check routine. To help solve the first bottle neck I highly recommend JSON, if used correctly it should reduce the size of the data to be passed from the server to the device and its very very easy to work with. It should also help with the second bottle neck, the check routine as you simply grab the returned data from the server, convert it to a JSON object representation with one line of code and then you are basically dealing with a NSDictionary of values.

Upvotes: 2

Related Questions