Skip to content

Commit 912bff2

Browse files
committed
New nested-transaction method
1 parent dd31fd1 commit 912bff2

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

FCModel/FCModel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ typedef NS_ENUM(NSInteger, FCModelChangeType) {
189189
+ (void)performTransaction:(BOOL (^)(void))block; // return YES to commit, NO to roll back
190190
+ (BOOL)isInTransaction;
191191

192+
// This variant has no control over commit/rollback; safe to potentially nest inside other transactions if you only want performance
193+
+ (void)performInTransactionForPerformance:(void (^)(void))block;
194+
192195
// Field info: You probably won't need this most of the time, but it's nice to have sometimes. FCModel's generating this privately
193196
// anyway, so you might as well have read-only access to it if it can help you avoid some code. (I've already needed it.)
194197
//

FCModel/FCModel.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,14 @@ + (BOOL)isInTransaction
11171117
return inTransaction;
11181118
}
11191119

1120+
+ (void)performInTransactionForPerformance:(void (^)(void))block
1121+
{
1122+
[self inDatabaseSync:^(FMDatabase *db) {
1123+
if (db.inTransaction) block();
1124+
else [self performTransaction:^BOOL{ block(); return YES; }];
1125+
}];
1126+
}
1127+
11201128
+ (void)performTransaction:(BOOL (^)(void))block
11211129
{
11221130
__block NSDictionary *changedFieldsToNotify = nil;

0 commit comments

Comments
 (0)