Cache comment list model to load comment faster

#define MODEL_ID @”CVCommentListSvcModel”

- (void)viewDidAppear:(BOOL)animated {

self.tableView.backgroundColor = BG_COLOR;
[self showBottomBar:YES animated:NO];

[self showLoading:YES];
[self loadCacheModel:[NSString stringWithFormat:@"%@_%@",MODEL_ID, self.key]];

- (void)modelDidFinishLoad:(CVAPIRequestModel*)model action:(NSString*)action {

if (model == _taskModel) {
_taskItem = _taskModel.taskItem;
[self showComments];
[CVCommentListSvcModel persistModel:_model withId:[NSString stringWithFormat:@"%@_%@", MODEL_ID, self.key]];
[self showComments];

if (!_isSwitchboardVisible && !_switchBoardCell) {
[self getSwitchBoardInfo];

CVWebSocket* webSocket = [CVWebSocket shared];
[webSocket subscribeToTile:_key];

[_model.items enumerateObjectsUsingBlock:^(CVCommentListItem* item, NSUInteger index, BOOL* stop) {
NSString* tileKey = [item commentKey];
[webSocket subscribeToTile:tileKey];

- (void)loadCacheModel:(NSString*)cacheId {
self.model = (CVCommentListSvcModel*)[CVCommentListSvcModel cachedModelWithId:cacheId];
if (_model == nil) {
_model = [[CVCommentListSvcModel alloc] init];
_model.taskKey = _key;
else {
[self modelDidFinishLoad:_model action:@""];
_model.delegate = self;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s