-
-
Notifications
You must be signed in to change notification settings - Fork 10
Add progress callback #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,11 @@ namespace PhenX.EntityFrameworkCore.BulkInsert.Options; | |
| /// </summary> | ||
| public class BulkInsertOptions | ||
| { | ||
| /// <summary> | ||
| /// Progress callback delegate to notify about the number of rows copied. | ||
| /// </summary> | ||
| public delegate void ProgressCallback(long rowsCopied); | ||
|
|
||
| /// <summary> | ||
| /// Move rows between tables instead of inserting them. | ||
| /// Only supported for PostgreSQL. | ||
|
|
@@ -31,6 +36,10 @@ public class BulkInsertOptions | |
| /// <term>SQLite</term> | ||
| /// <description>5</description> | ||
| /// </item> | ||
| /// <item> | ||
| /// <term>Oracle</term> | ||
| /// <description>50 000</description> | ||
| /// </item> | ||
| /// </list> | ||
| /// </summary> | ||
| public int BatchSize { get; set; } | ||
|
|
@@ -55,8 +64,30 @@ public class BulkInsertOptions | |
| /// </summary> | ||
| public int SRID { get; set; } = 4326; | ||
|
|
||
| /// <summary> | ||
| /// Number of rows after which the progress callback is invoked. | ||
| /// </summary> | ||
| public int? NotifyProgressAfter { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Callback to notify about the progress of the bulk insert operation. | ||
| /// </summary> | ||
| public ProgressCallback? OnProgress { get; set; } | ||
|
|
||
| internal int GetCopyTimeoutInSeconds() | ||
| { | ||
| return Math.Max(0, (int)CopyTimeout.TotalSeconds); | ||
| } | ||
|
|
||
| internal void HandleOnProgress(ref long rowsCopied) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I have really missed this PR. I think the ref is super weird here. Just to save a increment call on the provider level...
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's just a design choice on internal code, I find not so hard to understand and skips a few lines of code |
||
| { | ||
| rowsCopied++; | ||
|
|
||
| if (OnProgress == null || NotifyProgressAfter == null || NotifyProgressAfter <= 0 || rowsCopied % NotifyProgressAfter != 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| OnProgress(rowsCopied); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is advantage of a nullable here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No real advantages, I just could not decide which value was better