Skip to content

Commit

Permalink
= 4.2.7.6 =
Browse files Browse the repository at this point in the history
~ Clear cache when delete_user_item_and_result.
~ Tweak: get_user_items on LP_User_Items_DB.
  • Loading branch information
tungnxt89 committed Dec 24, 2024
1 parent 219e6c6 commit cfba67c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 9 additions & 2 deletions inc/Databases/class-lp-user-items-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Class LP_User_Items_DB
*
* @since 3.2.8.6
* @version 1.0.3
* @version 1.0.4
* @author tungnx
*/
class LP_User_Items_DB extends LP_Database {
Expand Down Expand Up @@ -102,7 +102,7 @@ public function update_data( array $data ): bool {
* @return array|null|int|string
* @throws Exception
* @since 4.1.6.9
* @version 1.0.3
* @version 1.0.4
*/
public function get_user_items( LP_User_Items_Filter $filter, int &$total_rows = 0 ) {
$filter->fields = array_merge( $filter->all_fields, $filter->fields );
Expand All @@ -127,6 +127,12 @@ public function get_user_items( LP_User_Items_Filter $filter, int &$total_rows =
$filter->where[] = $this->wpdb->prepare( 'AND ui.user_item_id = %d', $filter->user_item_id );
}

// Get by user_item_ids
if ( ! empty( $filter->user_item_ids ) ) {
$user_item_ids_format = LP_Helper::db_format_array( $filter->user_item_ids );
$filter->where[] = $this->wpdb->prepare( 'AND ui.user_item_id IN (' . $user_item_ids_format . ')', $filter->user_item_ids );
}

if ( $filter->user_id !== false ) {
$filter->where[] = $this->wpdb->prepare( 'AND ui.user_id = %d', $filter->user_id );
}
Expand Down Expand Up @@ -699,6 +705,7 @@ public function delete_user_items_old( int $user_id = 0, int $course_id = 0 ) {
LP_COURSE_CPT,
]
);
// Clear userCourseModel cache.
$key_cache = "userCourseModel/find/{$user_id}/{$course_id}/" . LP_COURSE_CPT;
$lpUserCourseCache = new LP_Cache();
$lpUserCourseCache->clear( $key_cache );
Expand Down
11 changes: 11 additions & 0 deletions inc/course/class-lp-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,17 @@ public function delete_user_item_and_result( array $user_course_ids ) {
// Delete on tb lp_user_items
$filter_delete = new LP_User_Items_Filter();
$filter_delete->user_item_ids = $user_item_ids_concat;
$user_items_rs = $lp_user_items_db->get_user_items( $filter_delete );

// For each to clear cache
foreach ( $user_items_rs as $user_item ) {
$lp_user_items_cache = new LP_User_Items_Cache();
$key_one = "userItemModel/find/{$user_item->user_id}/{$user_item->item_id}/{$user_item->item_type}";
$key_two = "userItemModel/find/{$user_item->user_id}/{$user_item->item_id}/{$user_item->item_type}/{$user_item->ref_id}/{$user_item->ref_type}";
$lp_user_items_cache->clear( $key_one );
$lp_user_items_cache->clear( $key_two );
}

$lp_user_items_db->remove_user_item_ids( $filter_delete );

// Delete user_itemmeta
Expand Down

0 comments on commit cfba67c

Please sign in to comment.