2
0

Fix slow fuzzy queries.

This commit is contained in:
Maarten Billemont 2017-04-12 23:41:17 -04:00
parent 2047422b08
commit 05391d893e
6 changed files with 19 additions and 18 deletions

@ -1 +1 @@
Subproject commit 6dc768f629339f45f0a287b80ba49c257d8c8205
Subproject commit d02256465aeaae87f21803195ba246cb114ca2ae

View File

@ -3688,7 +3688,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = "/bin/sh -e";
shellScript = "cd External/libsodium\n[[ -d libsodium-ios ]] && return\n\n# Xcode misinterpretes autogen.sh's stderr output as errors so we try to silence it.\n[[ -e configure ]] || { err=$(./autogen.sh 2>&1 >&3); } 3>&1 || { x=$?; echo >&2 \"$err\"; exit $x; }\n./dist-build/ios.sh";
shellScript = "cd External/libsodium\n[[ -d libsodium-ios ]] && exit\n\n# Xcode misinterpretes autogen.sh's stderr output as errors so we try to silence it.\n[[ -e configure ]] || { err=$(./autogen.sh 2>&1 >&3); } 3>&1 || { x=$?; echo >&2 \"$err\"; exit $x; }\n./dist-build/ios.sh";
showEnvVarsInLog = 0;
};
DA6556E314D55F3000841C99 /* Run Script: GIT version -> Info.plist */ = {

View File

@ -2345,7 +2345,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = "/bin/sh -e";
shellScript = "cd External/libsodium\n[[ -d libsodium-osx ]] && return\n\n# Xcode misinterpretes autogen.sh's stderr output as errors so we try to silence it.\n[[ -e configure ]] || { err=$(./autogen.sh 2>&1 >&3); } 3>&1 || { x=$?; echo >&2 \"$err\"; exit $x; }\n./dist-build/osx.sh";
shellScript = "cd External/libsodium\n[[ -d libsodium-osx ]] && exit\n\n# Xcode misinterpretes autogen.sh's stderr output as errors so we try to silence it.\n[[ -e configure ]] || { err=$(./autogen.sh 2>&1 >&3); } 3>&1 || { x=$?; echo >&2 \"$err\"; exit $x; }\n./dist-build/osx.sh";
showEnvVarsInLog = 0;
};
DA4EF9CB19FD4B600032ECB5 /* Run Script: genassets */ = {

View File

@ -17,6 +17,7 @@
//==============================================================================
#import <QuartzCore/QuartzCore.h>
#import <CoreData/CoreData.h>
#import "MPPasswordWindowController.h"
#import "MPMacAppDelegate.h"
#import "MPAppDelegate_Store.h"
@ -535,30 +536,33 @@
fuzzyRE = [NSRegularExpression regularExpressionWithPattern:@"(.)" options:0 error:nil];
} );
prof_new( @"updateSites" );
NSString *queryString = self.siteField.stringValue;
NSString *queryPattern;
if ([queryString length] < 13)
queryPattern = [queryString stringByReplacingMatchesOfExpression:fuzzyRE withTemplate:@"*$1*"];
else
// If query is too long, a wildcard per character makes the CoreData fetch take excessively long.
queryPattern = strf( @"*%@*", queryString );
NSString *queryPattern = [[queryString stringByReplacingMatchesOfExpression:fuzzyRE withTemplate:@"*$1"] stringByAppendingString:@"*"];
prof_rewind( @"queryPattern" );
NSMutableArray *fuzzyGroups = [NSMutableArray new];
[fuzzyRE enumerateMatchesInString:queryString options:0 range:NSMakeRange( 0, queryString.length )
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
[fuzzyGroups addObject:[queryString substringWithRange:result.range]];
}];
prof_rewind( @"fuzzyRE" );
[MPMacAppDelegate managedObjectContextPerformBlock:^(NSManagedObjectContext *context) {
prof_rewind( @"moc" );
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass( [MPSiteEntity class] )];
fetchRequest.sortDescriptors = @[ [[NSSortDescriptor alloc] initWithKey:@"lastUsed" ascending:NO] ];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"(%@ == '' OR name LIKE[cd] %@) AND user == %@",
queryPattern, queryPattern, [MPMacAppDelegate get].activeUserOID];
prof_rewind( @"fetchRequest" );
NSError *error = nil;
NSArray *siteResults = [context executeFetchRequest:fetchRequest error:&error];
if (!siteResults) {
prof_finish( @"executeFetchRequest: %@ // %@", fetchRequest.predicate, [error fullDescription] );
err( @"While fetching sites for completion: %@", [error fullDescription] );
return;
}
prof_rewind( @"executeFetchRequest: %@", fetchRequest.predicate );
BOOL exact = NO;
NSMutableArray *newSites = [NSMutableArray arrayWithCapacity:[siteResults count]];
@ -566,10 +570,12 @@
[newSites addObject:[[MPSiteModel alloc] initWithEntity:site fuzzyGroups:fuzzyGroups]];
exact |= [site.name isEqualToString:queryString];
}
prof_rewind( @"newSites: %u, exact: %d", (uint)[siteResults count], exact );
if (!exact && [queryString length]) {
MPUserEntity *activeUser = [[MPAppDelegate_Shared get] activeUserInContext:context];
[newSites addObject:[[MPSiteModel alloc] initWithName:queryString forUser:activeUser]];
}
prof_finish( @"newSites: %@", newSites );
dbg( @"newSites: %@", newSites );
if (![newSites isEqualToArray:self.sites])

View File

@ -80,7 +80,6 @@
self.uses = entity.uses_;
self.counter = [entity isKindOfClass:[MPGeneratedSiteEntity class]]? [(MPGeneratedSiteEntity *)entity counter]: 0;
self.loginGenerated = entity.loginGenerated;
NSLog( @"%@: loginGenerated: %d", self.name, self.loginGenerated );
// Find all password types and the index of the current type amongst them.
[self updateContent:entity];
@ -276,7 +275,6 @@
PearlMainQueue( ^{
self.loginName = loginName;
NSLog( @"%@: loginGenerated: %d, loginName: %@", self.name, self.loginGenerated, loginName );
} );
}

View File

@ -5,24 +5,21 @@
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#define PEARL_WITH_SCRYPT
#define PEARL_WITH_MESSAGEUI
#define PEARL
#define PEARL_CRYPTO
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#if TARGET_OS_IOS
#define PEARL_UIKIT
#endif
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
#elif TARGET_OS_OSX
#define PEARL_COCOA
#endif
#import "Pearl.h"
#import "Pearl-Crypto.h"
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
#if TARGET_OS_IOS
#import "Pearl-UIKit.h"
#endif
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED
#elif TARGET_OS_OSX
#import "Pearl-Cocoa.h"
#endif
#endif