2009-11-25 2 views
1

업데이트 :대량 갱신 및 가끔 삽입 (coredata) - 너무 느린

나 '..

여기에 지혜 혜택을 누릴 수, Comparing Two Arrays

안녕 얘들 아 : 현재 NSSET의 minusSet 링크로보고 처음 응용 프로그램에서 Coredata를 사용하여, 데이터 파일을 다운로드하고 500 개의 객체 (각각 60 개의 속성이 있음)를 삽입합니다. - 빠르고, 아무런 문제가 없습니다.

각 후속 시작 파일의 업데이트 된 버전을 다운로드합니다. 여기에서 모든 기존 개체의 속성 (5 속성 제외)을 업데이트하고 다운로드 한 파일에 추가 된 항목에 대해 새 속성을 만들어야합니다.

그래서, 처음 실행 나는

내가 두 배열, 기존 하나 다운로드 하나를 만들 ... 500 개체가 ... 일주일 후 내 파일이 지금은 507 개 항목을 포함 말할 수. 각 배열의 개수가 동일한 경우

NSArray *peopleArrayDownloaded = [CoreDataHelper getObjectsFromContext:@"person" :@"person_id" :YES :managedObjectContextPeopleTemp]; 
NSArray *peopleArrayExisting = [CoreDataHelper getObjectsFromContext:@"person" :@"person_id" :YES :managedObjectContextPeople]; 

후, 난 그냥 이렇게 :

NSUInteger index = 0; 
if ([peopleArrayExisting count] == [peopleArrayDownloaded count]) { 
    NSLog(@"Number of people downloaded is same as the number of people existing"); 
    for (person *existingPerson in peopleArrayExisting) { 
     person *tempPerson = [peopleArrayDownloaded objectAtIndex:index]; 
     // NSLog(@"Updating id: %@ with id: %@",existingPerson.person_id,tempPerson.person_id); 
     // I have 60 attributes which I to update on each object, is there a quicker way other than overwriting existing? 
     index++; 
    } 
} else { 
    NSLog(@"Number of people downloaded is different to number of players existing"); 

이제 느린 부분을 온다.

내가 사용 결국이 (어떤이 tooooo 느리게) :

  NSLog(@"Need people added to the league"); 
     for (person *tempPerson in peopeArrayDownloaded) { 
      NSPredicate *predicate = [NSPredicate predicateWithFormat:@"person_id = %@",tempPerson.person_id]; 
      // NSLog(@"Searching for existing person, person_id: %@",existingPerson.person_id); 
      NSArray *filteredArray = [peopleArrayExisting filteredArrayUsingPredicate:predicate]; 
      if ([filteredArray count] == 0) { 
       NSLog(@"Couldn't find an existing person in the downloaded file. Adding.."); 
       person *newPerson = [NSEntityDescription insertNewObjectForEntityForName:@"person" inManagedObjectContext:managedObjectContextPeople]; 

내 다운로드 한 파일에서 추가 항목을 참조 인덱스 항목의 새로운 배열을 생성하는 방법이 있나요?

부수적으로, 내 tableViews에서 NSFetchedResultsController를 사용하여 속성을 업데이트하면 [셀 setNeedsDisplay]; .. 셀당 약 60 회, 좋은 것은 아니며 앱을 중단시킬 수 있습니다. 읽기

감사합니다 :) 나는 여전히 코어 데이터 프레임 워크를 사용하여 새로운 해요,하지만 내 생각 엔이 문제가 루프 당신이 게시 한에 달려 있다는 것을 말함으로써 시작하겠습니다

+0

참고 : 선택자에서 이름없는 인수를 사용하는 것은 좋지 않습니다. – retainCount

+0

댓글을 주셔서 감사합니다. 아직 배우고 있습니다. 내가 어디에서 이러는거야? – iOSDevil

답변

3

.

루프를 보면 실행될 때마다 새로운 NSPredicate 개체가 생성 된 다음 기존 배열을 필터링하여 일치하는 항목을 찾습니다. 작은 데이터 세트에서이 기술은 성능이 약간 떨어지는 것처럼 보입니다. 그러나 대용량 데이터 세트를 사용하면 제공 한 이름 만 다른 NSPredicate 개체를 만드는 데 많은 시간을 소비하게됩니다. 단일 술어를 작성한 다음 변수 대체를 사용하여 검색을 수행하는 방법을 살펴 보는 것이 좋습니다. 조건부 변수 사용에 대한 자세한 내용은 다음을 참조하십시오. http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdImporting.html#//apple_ref/doc/uid/TP40003174

보조 노트로 데이터를 정렬 한 방법과 검색 작업을 수행하는 방법을 고려해야합니다. 그리고 또 다른 사실은 NSPredicate 객체를 해제하지 않는다는 것입니다. 따라서 메모리를 버리는 것뿐입니다.