File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -47,14 +47,24 @@ class Bulk
47
47
*/
48
48
public $ operationCount = 0 ;
49
49
50
+ /**
51
+ * Operation count which will trigger autocommit
52
+ * @var int
53
+ */
54
+ public $ autocommitAfter = 0 ;
55
+
50
56
51
57
/**
52
58
* Bulk constructor.
53
59
* @param Query $query
60
+ * @param int $autocommitAfter
54
61
*/
55
- public function __construct (Query $ query )
62
+ public function __construct (Query $ query, $ autocommitAfter = 0 )
56
63
{
64
+
57
65
$ this ->query = $ query ;
66
+ $ this ->autocommitAfter = intval ($ autocommitAfter );
67
+
58
68
}
59
69
60
70
/**
@@ -186,6 +196,10 @@ public function action($actionType, $data = [])
186
196
$ this ->operationCount ++;
187
197
188
198
$ this ->reset ();
199
+
200
+ if ($ this ->autocommitAfter > 0 && $ this ->operationCount >= $ this ->autocommitAfter ) {
201
+ $ this ->commit ();
202
+ }
189
203
}
190
204
191
205
/**
@@ -217,9 +231,10 @@ public function reset()
217
231
public function commit ()
218
232
{
219
233
220
- $ this ->query ->connection ->bulk ($ this ->body );
234
+ $ result = $ this ->query ->connection ->bulk ($ this ->body );
221
235
$ this ->operationCount = 0 ;
222
236
$ this ->body = [];
223
237
238
+ return $ result ;
224
239
}
225
240
}
You can’t perform that action at this time.
0 commit comments