Skip to content
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

Update order modifier queries #3479

Open
wants to merge 33 commits into
base: release/T25.imp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
88e18d7
Create dedicated Status trait
JPry Dec 11, 2024
fe14d5b
Sort imports alphabetically
JPry Dec 11, 2024
a176a60
Use Status trait, and remove methods from Valid_Types trait
JPry Dec 11, 2024
0794b1e
Add wrapper functions to get table names
JPry Dec 24, 2024
13d4664
Create separate method for adding ->from() to the query builder
JPry Dec 24, 2024
ce4735b
Use method parameters for JOIN aliases
JPry Dec 24, 2024
0104033
Shorten names of class properties
JPry Dec 25, 2024
00f649c
Update get_modifier_id() to match actual behavior of the code
JPry Dec 25, 2024
9b00117
Simplify required field logic
JPry Dec 25, 2024
77cd060
Add get_modifier_by_applied_to() method
JPry Dec 25, 2024
eb86580
Use Factory class for tests
JPry Jan 9, 2025
6330e38
Tweak formatting
JPry Jan 9, 2025
0edc275
Use QueryBuilder instead of raw SQL
JPry Jan 9, 2025
f8a79b6
Use factory for modifier model
JPry Jan 9, 2025
a681947
Use direct methods for column headers
JPry Jan 9, 2025
2b6482b
Use new method for getting fees
JPry Jan 9, 2025
84c666b
Remove unused properties
JPry Jan 9, 2025
9b523c0
Correct the handling of raw amount
JPry Jan 10, 2025
f38af32
Handle orderby in the parameters
JPry Jan 10, 2025
33e42a1
Handle more query parameters
JPry Jan 10, 2025
139e9ea
Correctly handle orderby options
JPry Jan 10, 2025
2d9c6cb
Use consistent methods for handling query args
JPry Jan 10, 2025
e750f1e
Add method for getting the count of items found by search
JPry Jan 10, 2025
32a3ae1
Update item retrieval with new methods
JPry Jan 10, 2025
9baed4f
Add new fee repo test
JPry Jan 10, 2025
6a3cf22
Add changelog file
JPry Jan 10, 2025
65c5bd6
Fix PHPCS issues
JPry Jan 10, 2025
de6da83
Replace tribe_get_request_var() with tec_get_request_var()
JPry Jan 10, 2025
691698c
Remove unused parameter
JPry Jan 10, 2025
47b170b
Rename test file and use correct number of test cases
JPry Jan 10, 2025
ec0e2de
Fix over-zealous find/replace: use tribe_get_request_vars()
JPry Jan 10, 2025
c8f70bf
Fix the tests
JPry Jan 10, 2025
5114f90
Only run the count query if necessary
JPry Jan 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/feature-ET-2268-update-modifier-queries
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: performance

Enhance the performance of order modifier database queries [ET-2268]
5 changes: 2 additions & 3 deletions src/Tickets/Commerce/Order_Modifiers/API/Fees.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ public function __construct(
Manager $manager
) {
parent::__construct( $container );
$this->modifiers_repository = $fee_repository;
JPry marked this conversation as resolved.
Show resolved Hide resolved
$this->relationships = $relationships;
$this->manager = $manager;
$this->relationships = $relationships;
$this->manager = $manager;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public function __construct(
$this->manager = $manager;

// Set up the order modifiers repository for accessing fee data.
$this->modifiers_repository = $fees_repository;
$this->order_modifiers_relationship_repository = $order_modifier_relationship;
}

Expand Down
10 changes: 5 additions & 5 deletions src/Tickets/Commerce/Order_Modifiers/Models/Order_Modifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use TEC\Common\StellarWP\Models\Model;
use TEC\Common\StellarWP\Models\ModelQueryBuilder;
use TEC\Tickets\Commerce\Order_Modifiers\Data_Transfer_Objects\Order_Modifier_DTO;
use TEC\Tickets\Commerce\Order_Modifiers\Repositories\Order_Modifiers as Repository;
use TEC\Tickets\Commerce\Order_Modifiers\Factory;
use TEC\Tickets\Commerce\Order_Modifiers\Values\Float_Value;
use TEC\Tickets\Commerce\Order_Modifiers\Values\Percent_Value;
use TEC\Tickets\Commerce\Order_Modifiers\Values\Positive_Integer_Value;
Expand Down Expand Up @@ -84,7 +84,7 @@ public static function find( $id ): ?self {
return null;
}

return ( new Repository( static::$order_modifier_type ) )->find_by_id( $id );
return Factory::get_repository_for_type( static::$order_modifier_type )->find_by_id( $id );
}

/**
Expand Down Expand Up @@ -116,7 +116,7 @@ public static function create( array $attributes ): self {
* @return static
*/
public function save(): self {
$repository = new Repository( $this->modifier_type );
$repository = Factory::get_repository_for_type( $this->modifier_type );
if ( $this->id ) {
$repository->update( $this );

Expand All @@ -136,7 +136,7 @@ public function save(): self {
* @return bool Whether the model was deleted.
*/
public function delete(): bool {
return ( new Repository( $this->modifier_type ) )->delete( $this );
return Factory::get_repository_for_type( $this->modifier_type )->delete( $this );
}

/**
Expand All @@ -147,7 +147,7 @@ public function delete(): bool {
* @return ModelQueryBuilder The query builder instance.
*/
public static function query(): ModelQueryBuilder {
return tribe( Repository::class )->query();
return Factory::get_repository_for_type( static::$order_modifier_type )->prepareQuery();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Tickets/Commerce/Order_Modifiers/Modifiers/Coupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ public function render_edit( array $context ): void {
* @return array The context data ready for rendering the form.
*/
public function map_context_to_template( array $context ): array {
$order_modifier_coupon_limit_meta_value = $this->order_modifiers_meta_repository->find_by_order_modifier_id_and_meta_key( $context['modifier_id'], 'coupons_available' )->meta_value ?? '';
$limit_value = $this->meta_repository->find_by_order_modifier_id_and_meta_key( $context['modifier_id'], 'coupons_available' )->meta_value ?? '';
return [
'order_modifier_display_name' => $context['display_name'] ?? '',
'order_modifier_slug' => $context['slug'] ?? $this->generate_unique_slug(),
'order_modifier_sub_type' => $context['sub_type'] ?? '',
'order_modifier_fee_amount_cents' => $this->convert_from_raw_amount( $context['raw_amount'] ?? 0 ),
'order_modifier_status' => $context['status'] ?? '',
'order_modifier_coupon_limit' => $order_modifier_coupon_limit_meta_value ?? '',
'order_modifier_coupon_limit' => $limit_value ?? '',
];
}

Expand Down
4 changes: 2 additions & 2 deletions src/Tickets/Commerce/Order_Modifiers/Modifiers/Fee.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function render_edit( array $context ): void {
* @return array The context data ready for rendering the form.
*/
public function map_context_to_template( array $context ): array {
$order_modifier_fee_applied_to = $this->order_modifiers_meta_repository->find_by_order_modifier_id_and_meta_key( $context['modifier_id'], 'fee_applied_to' )->meta_value ?? '';
$order_modifier_fee_applied_to = $this->meta_repository->find_by_order_modifier_id_and_meta_key( $context['modifier_id'], 'fee_applied_to' )->meta_value ?? '';
return [
'order_modifier_display_name' => $context['display_name'] ?? '',
'order_modifier_slug' => $context['slug'] ?? $this->generate_unique_slug(),
Expand All @@ -295,6 +295,6 @@ public function map_context_to_template( array $context ): array {
* @return array The list of posts related to the modifier.
*/
public function get_active_on( $modifier_id ) {
return $this->order_modifiers_relationship_repository->find_by_modifier_id( $modifier_id );
return $this->relationship_repository->find_by_modifier_id( $modifier_id );
}
}
Loading
Loading