-
Notifications
You must be signed in to change notification settings - Fork 193
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
Feature: Update Campaign Donation Query #7630
Feature: Update Campaign Donation Query #7630
Conversation
DB::table('give_donationmeta') | ||
->insert([ | ||
'donation_id' => $donation->ID, | ||
'meta_key' => DonationMetaKeys::CAMPAIGN_ID, | ||
'meta_value' => $campaignId, | ||
]); |
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.
Seems like this could be accomplished as a single insert of many rows?
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.
Yes, with SQL. With WPDB, not really. I would love to have that feature. Maybe we should consider updating the insert
method to support that.
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.
Seems like a shame to knowingly have a nasty N+1 issue here that we could definitely circumvent just because of a lack of a WPDB feature. I think it's worth taking the moment to build the insert many feature for this.
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.
@JasonTheAdams, I have been thinking about this in the past. Since data for inserting will probably be collected inside the loop, I thought having something like this might be handy:
$qb = DB::table('give_donationmeta');
foreach($data as $row) {
$qb->set([
'donation_id' => $row->id,
'meta_key' => $row->key,
'meta_value' => $row->value,
]);
}
$qb->insert();
This approach will require altering the insert
method to be something like this:
public function insert($data = [], $format = null)
{
// collection represents collected data for insert
if ($this->collection instanceof Collection) {
return DB::query($this->getInsertIntoSQL());
}
if (empty($data)) {
throw new InvalidArgumentException('data cannot be empty');
}
return DB::insert(
$this->getTable(),
$data,
$format
);
}
@JasonTheAdams @kjohnson @jonwaldstein I added two new methods ( |
@@ -22,6 +23,12 @@ trait CRUD | |||
*/ | |||
public function insert($data, $format = null) | |||
{ | |||
if (array_is_list($data)) { |
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.
@alaca Do we have a polyfill for this somewhere? This is a PHP 8.1 function.
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.
@JasonTheAdams Yeah. I installed and am using the stellarwp/arrays package now.
…-donation-query-GIVE-1344 # Conflicts: # src/Campaigns/Repositories/CampaignRepository.php
Description
This PR touches several places to update the
CampaignDonationQuery
class so that we are no longer using thegive_campaign_forms
lookup table to get donations. Since we don't have a donations table, the only fairly reasonable option was to add another meta field that will reference the campaign ID. The donation model is updated so that it is now possible to get a campaign from a donation object ($donation->campaign->id
). The donation repository has also been updated to store the campaign ID as a donation meta. Also, Revenue DonationHandler is updated to insert the campaign ID on each donation, although I'm not entirely sure we need the campaign ID column in this table. It might be handy for reports.Affects
Donation model
Donations repository
Donation meta
Give container
Revenue Donation Handler
Pre-review Checklist
@unreleased
tags included in DocBlocks