Skip to content

Commit

Permalink
remove old classes and update with our changes
Browse files Browse the repository at this point in the history
  • Loading branch information
remyperona committed Oct 4, 2024
1 parent 6af8988 commit 027aaed
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 7,162 deletions.
3 changes: 2 additions & 1 deletion inc/Dependencies/BerlinDB/Database/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*
* @since 1.0.0
*/
#[\AllowDynamicProperties]
class Base {

/**
Expand Down Expand Up @@ -280,7 +281,7 @@ protected function set_vars( $args = array() ) {
*
* @since 1.0.0
*
* @return \wpdb Database interface, or False if not set
* @return \wpdb|false Database interface, or False if not set
*/
protected function get_db() {

Expand Down
31 changes: 18 additions & 13 deletions inc/Dependencies/BerlinDB/Database/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Query extends Base {
* @since 1.0.0
* @var string
*/
protected $table_schema = '\\WP_Rocket\Dependencies\BerlinDB\\Database\\Schema';
protected $table_schema = '\\WP_Rocket\\Dependencies\\BerlinDB\\Database\\Schema';

/** Item ******************************************************************/

Expand Down Expand Up @@ -113,7 +113,7 @@ class Query extends Base {
* @since 1.0.0
* @var mixed
*/
protected $item_shape = '\\WP_Rocket\Dependencies\BerlinDB\\Database\\Row';
protected $item_shape = '\\WP_Rocket\\Dependencies\\BerlinDB\\Database\\Row';

/** Cache *****************************************************************/

Expand Down Expand Up @@ -342,12 +342,13 @@ public function __construct( $query = array() ) {
* @since 1.0.0
*
* @param string|array $query Array or URL query string of parameters.
* @param bool $use_cache Use DB cache or not. (custom parameter added by us!)
* @return array|int List of items, or number of items when 'count' is passed as a query var.
*/
public function query( $query = array() ) {
public function query( $query = array(), bool $use_cache = true ) {
$this->parse_query( $query );

return $this->get_items();
return $this->get_items( $use_cache );
}

/** Private Setters *******************************************************/
Expand Down Expand Up @@ -857,9 +858,11 @@ private function get_item_raw( $column_name = '', $column_value = '' ) {
*
* @since 1.0.0
*
* @param bool $use_cache Use DB cache or not. (custom parameter added by us!)
*
* @return array|int List of items, or number of items when 'count' is passed as a query var.
*/
private function get_items() {
private function get_items( bool $use_cache = true ) {

/**
* Fires before object items are retrieved.
Expand All @@ -880,7 +883,7 @@ private function get_items() {

// Check the cache
$cache_key = $this->get_cache_key();
$cache_value = $this->cache_get( $cache_key, $this->cache_group );
$cache_value = $use_cache ? $this->cache_get( $cache_key, $this->cache_group ) : false;

// No cache value
if ( false === $cache_value ) {
Expand All @@ -889,14 +892,16 @@ private function get_items() {
// Set the number of found items
$this->set_found_items( $item_ids );

// Format the cached value
$cache_value = array(
'item_ids' => $item_ids,
'found_items' => intval( $this->found_items ),
);
if ( $use_cache ) {
// Format the cached value
$cache_value = array(
'item_ids' => $item_ids,
'found_items' => intval( $this->found_items ),
);

// Add value to the cache
$this->cache_add( $cache_key, $cache_value, $this->cache_group );
// Add value to the cache
$this->cache_add( $cache_key, $cache_value, $this->cache_group );
}

// Value exists in cache
} else {
Expand Down
Loading

0 comments on commit 027aaed

Please # to comment.