Skip to content

Commit

Permalink
https://github.com/yapstudios/YapDatabase/pull/547
Browse files Browse the repository at this point in the history
  • Loading branch information
small3flower committed Sep 7, 2022
1 parent 11de36e commit 4b81847
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -52,8 +50,8 @@
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -66,29 +64,16 @@
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "4">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/TestModuleMap-iOS">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC6266C81D80D3E000557968"
BuildableName = "TestModuleMap-watchOS.app"
BlueprintName = "TestModuleMap-watchOS"
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC6266C81D80D3E000557968"
BuildableName = "TestModuleMap-watchOS.app"
BlueprintName = "TestModuleMap-watchOS"
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand All @@ -97,27 +82,16 @@
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
launchAutomaticallySubstyle = "4">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/TestModuleMap-iOS">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC6266C81D80D3E000557968"
BuildableName = "TestModuleMap-watchOS.app"
BlueprintName = "TestModuleMap-watchOS"
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC6266C81D80D3E000557968"
BuildableName = "TestModuleMap-watchOS.app"
BlueprintName = "TestModuleMap-watchOS"
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -52,8 +50,8 @@
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -66,29 +64,16 @@
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "8">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/TestModuleMap-iOS">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC6266C81D80D3E000557968"
BuildableName = "TestModuleMap-watchOS.app"
BlueprintName = "TestModuleMap-watchOS"
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC6266C81D80D3E000557968"
BuildableName = "TestModuleMap-watchOS.app"
BlueprintName = "TestModuleMap-watchOS"
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand All @@ -97,27 +82,16 @@
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
launchAutomaticallySubstyle = "8">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/TestModuleMap-iOS">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC6266C81D80D3E000557968"
BuildableName = "TestModuleMap-watchOS.app"
BlueprintName = "TestModuleMap-watchOS"
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC6266C81D80D3E000557968"
BuildableName = "TestModuleMap-watchOS.app"
BlueprintName = "TestModuleMap-watchOS"
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
Expand All @@ -52,8 +50,8 @@
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -65,57 +63,33 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/TestModuleMap-iOS">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC6266C81D80D3E000557968"
BuildableName = "TestModuleMap-watchOS.app"
BlueprintName = "TestModuleMap-watchOS"
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC6266C81D80D3E000557968"
BuildableName = "TestModuleMap-watchOS.app"
BlueprintName = "TestModuleMap-watchOS"
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/TestModuleMap-iOS">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC6266C81D80D3E000557968"
BuildableName = "TestModuleMap-watchOS.app"
BlueprintName = "TestModuleMap-watchOS"
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DC6266C81D80D3E000557968"
BuildableName = "TestModuleMap-watchOS.app"
BlueprintName = "TestModuleMap-watchOS"
ReferencedContainer = "container:YapDatabase.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
33 changes: 25 additions & 8 deletions YapDatabase/Extensions/AutoView/YapDatabaseAutoViewTransaction.m
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,13 @@ - (void)insertRowid:(int64_t)rowid
object:&anotherObject
forRowid:anotherRowid];

return sortingBlock(databaseTransaction, group,
collectionKey.collection, collectionKey.key, object,
another.collection, another.key, anotherObject);
if (object && anotherObject) {
return sortingBlock(databaseTransaction, group,
collectionKey.collection, collectionKey.key, object,
another.collection, another.key, anotherObject);
} else {
return NSOrderedAscending;
}
}
else if (sorting->blockType == YapDatabaseBlockTypeWithMetadata)
{
Expand Down Expand Up @@ -640,9 +644,14 @@ - (void)insertRowid:(int64_t)rowid
metadata:&anotherMetadata
forRowid:anotherRowid];

return sortingBlock(databaseTransaction, group,
collectionKey.collection, collectionKey.key, object, metadata,
another.collection, another.key, anotherObject, anotherMetadata);
if (object && anotherObject) {
return sortingBlock(databaseTransaction, group,
collectionKey.collection, collectionKey.key, object, metadata,
another.collection, another.key, anotherObject, anotherMetadata);
} else {
return NSOrderedAscending;
}

}

#pragma clang diagnostic pop
Expand Down Expand Up @@ -1485,7 +1494,11 @@ - (NSRange)findRangeInGroup:(NSString *)group using:(YapDatabaseViewFind *)find
id object = nil;
[databaseTransaction getCollectionKey:&ck object:&object forRowid:rowid];

return findBlock(ck.collection, ck.key, object);
if (ck && object) {
return findBlock(ck.collection, ck.key, object);
} else {
return NSOrderedAscending;
}

#pragma clang diagnostic pop
};
Expand Down Expand Up @@ -1532,7 +1545,11 @@ - (NSRange)findRangeInGroup:(NSString *)group using:(YapDatabaseViewFind *)find
id metadata = nil;
[databaseTransaction getCollectionKey:&ck object:&object metadata:&metadata forRowid:rowid];

return findBlock(ck.collection, ck.key, object, metadata);
if (ck && object) {
return findBlock(ck.collection, ck.key, object, metadata);
} else {
return NSOrderedAscending;
}

#pragma clang diagnostic pop
};
Expand Down
12 changes: 6 additions & 6 deletions YapDatabase/Extensions/AutoView/YapDatabaseViewTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ typedef NSComparisonResult (^YapDatabaseViewSortingWithKeyBlock)

typedef NSComparisonResult (^YapDatabaseViewSortingWithObjectBlock)
(YapDatabaseReadTransaction *transaction, NSString *group,
NSString *collection1, NSString *key1, id object1,
NSString *collection2, NSString *key2, id object2);
NSString *collection1, NSString *key1, _Nullable id object1,
NSString *collection2, NSString *key2, _Nullable id object2);

typedef NSComparisonResult (^YapDatabaseViewSortingWithMetadataBlock)
(YapDatabaseReadTransaction *transaction, NSString *group,
Expand All @@ -131,8 +131,8 @@ typedef NSComparisonResult (^YapDatabaseViewSortingWithMetadataBlock)

typedef NSComparisonResult (^YapDatabaseViewSortingWithRowBlock)
(YapDatabaseReadTransaction *transaction, NSString *group,
NSString *collection1, NSString *key1, id object1, _Nullable id metadata1,
NSString *collection2, NSString *key2, id object2, _Nullable id metadata2);
NSString *collection1, NSString *key1, _Nullable id object1, _Nullable id metadata1,
NSString *collection2, NSString *key2, _Nullable id object2, _Nullable id metadata2);

+ (instancetype)withKeyBlock:(YapDatabaseViewSortingWithKeyBlock)block;
+ (instancetype)withObjectBlock:(YapDatabaseViewSortingWithObjectBlock)block;
Expand Down Expand Up @@ -207,13 +207,13 @@ typedef NSComparisonResult (^YapDatabaseViewFindWithKeyBlock)
(NSString *collection, NSString *key);

typedef NSComparisonResult (^YapDatabaseViewFindWithObjectBlock)
(NSString *collection, NSString *key, id object);
(NSString *collection, NSString *key, _Nullable id object);

typedef NSComparisonResult (^YapDatabaseViewFindWithMetadataBlock)
(NSString *collection, NSString *key, _Nullable id metadata);

typedef NSComparisonResult (^YapDatabaseViewFindWithRowBlock)
(NSString *collection, NSString *key, id object, _Nullable id metadata);
(NSString *collection, NSString *key, _Nullable id object, _Nullable id metadata);

+ (instancetype)withKeyBlock:(YapDatabaseViewFindWithKeyBlock)findBlock;
+ (instancetype)withObjectBlock:(YapDatabaseViewFindWithObjectBlock)findBlock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,9 @@ - (BOOL)enumerateKeysAndObjectsMatchingQuery:(YapDatabaseQuery *)query
id object = nil;
[self->databaseTransaction getCollectionKey:&ck object:&object forRowid:rowid];

block(ck.collection, ck.key, object, stop);
if (ck && object) {
block(ck.collection, ck.key, object, stop);
}
}];

return result;
Expand All @@ -1175,7 +1177,9 @@ - (BOOL)enumerateRowsMatchingQuery:(YapDatabaseQuery *)query
id metadata = nil;
[self->databaseTransaction getCollectionKey:&ck object:&object metadata:&metadata forRowid:rowid];

block(ck.collection, ck.key, object, metadata, stop);
if (ck && object) {
block(ck.collection, ck.key, object, metadata, stop);
}
}];

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,9 @@ - (BOOL)enumerateKeysAndObjectsMatchingQuery:(YapDatabaseQuery *)query
id object = nil;
[self->databaseTransaction getCollectionKey:&ck object:&object forRowid:rowid];

block(ck.collection, ck.key, object, stop);
if (ck && object) {
block(ck.collection, ck.key, object, stop);
}
}];

return result;
Expand Down
7 changes: 7 additions & 0 deletions YapDatabase/Extensions/View/YapDatabaseViewTransaction.m
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,13 @@ - (void)insertRowid:(int64_t)rowid collectionKey:(YapCollectionKey *)collectionK

NSString *pageKey = pageMetadata->pageKey;
YapDatabaseViewPage *page = [self pageForPageKey:pageKey];

NSAssert(page != nil, @"Missing page in group(%@)", group);

if (!page) {
YDBLogError(@"Missing page in group(%@)! Error inserting key(%@) collection(%@) in group(%@) at index(%lu) with page(nil) pageOffset(%lu)", group, collectionKey.key, collectionKey.collection, group, index, pageOffset);
return;
}

YDBLogVerbose(@"Inserting key(%@) collection(%@) in group(%@) at index(%lu) with page(%@) pageOffset(%lu)",
collectionKey.key, collectionKey.collection, group,
Expand Down
Loading

0 comments on commit 4b81847

Please sign in to comment.