Skip to content

Commit

Permalink
* Several SQL Query optimizations reducing some query times even furt…
Browse files Browse the repository at this point in the history
…her - ADDED

* GD > Single Next Prev not filtering by same location - FIXED
* Add listing zip and region discovery improvements - ADDED
  • Loading branch information
stiofan committed Feb 20, 2024
1 parent 4be3183 commit b48ce7d
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 101 deletions.
120 changes: 60 additions & 60 deletions includes/abstracts/abstract-geodir-rest-posts-controller.php

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions includes/admin/class-geodir-admin-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public static function install() {
//()->query->add_endpoints();
//_API::add_endpoint();
//_Auth::add_endpoint();

self::create_cron_jobs();

// Queue upgrades/setup wizard
Expand All @@ -194,7 +194,7 @@ public static function install() {
// Trigger action
do_action( 'geodirectory_installed' );
}

/**
* Reset any notices added to admin.
*
Expand All @@ -203,7 +203,7 @@ public static function install() {
private static function remove_admin_notices() {
GeoDir_Admin_Notices::remove_all_notices();
}

/**
* Is this a brand new GeoDirectory install?
*
Expand Down Expand Up @@ -290,7 +290,7 @@ public static function insert_default_fields($post_type = 'gd_place'){
*/
public static function insert_default_tabs($post_type = 'gd_place'){
$fields = array();

// Profile / description
$fields[] = array(
'post_type' => $post_type,
Expand Down Expand Up @@ -358,7 +358,7 @@ public static function insert_default_tabs($post_type = 'gd_place'){
}
}
}

/**
* See if we need to show or run database updates during install.
*
Expand Down Expand Up @@ -435,7 +435,7 @@ public static function update_db_version( $version = null ) {
* @return array
*/
public static function cron_schedules( $schedules ) {
// Kadence starter templates page is broken when monthly schedule option is set.
// Kadence starter templates page is broken when monthly schedule option is set.
if ( ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'kadence-starter-templates' ) || ( ! empty( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], array( 'kadence_check_plugin_data', 'kadence_import_get_template_data', 'kadence_import_install_plugins' ) ) ) ) {
return $schedules;
}
Expand Down Expand Up @@ -504,7 +504,7 @@ public static function create_pages() {
'content' => GeoDir_Defaults::page_details_content(false, $gutenberg),
),


) );

foreach ( $pages as $key => $page ) {
Expand Down Expand Up @@ -553,7 +553,7 @@ private static function create_options() {

// Include settings so that we can run through defaults
include_once( dirname( __FILE__ ) . '/class-geodir-admin-settings.php' );

$current_settings = geodir_get_settings();

$settings = GeoDir_Admin_Settings::get_settings_pages();
Expand Down Expand Up @@ -695,14 +695,14 @@ public static function get_schema() {
// Table for storing place attribute - these are user defined
$tables .= " CREATE TABLE " . $plugin_prefix . "gd_place_detail (
".implode (", \n",self::db_cpt_default_columns()).",
".implode (", \n",self::db_cpt_default_keys())."
".implode (", \n",self::db_cpt_default_keys())."
) $collate; ";
}else{
foreach($post_types as $post_type => $cpt){
// Table for storing place attribute - these are user defined
$tables .= " CREATE TABLE " . $plugin_prefix . $post_type . "_detail (
".implode (", \n",self::db_cpt_default_columns($cpt, $post_type)).",
".implode (", \n",self::db_cpt_default_keys($cpt, $post_type))."
".implode (", \n",self::db_cpt_default_keys($cpt, $post_type))."
) $collate; ";
}

Expand All @@ -713,20 +713,22 @@ public static function get_schema() {
// Table for storing place images - these are user defined
$tables .= " CREATE TABLE " . GEODIR_ATTACHMENT_TABLE . " (
ID int(11) NOT NULL AUTO_INCREMENT,
post_id int(11) NOT NULL,
post_id bigint(20) NOT NULL,
date_gmt datetime NULL default null,
user_id int(11) DEFAULT NULL,
other_id int(11) DEFAULT NULL,
title varchar(254) NULL DEFAULT NULL,
caption varchar(254) NULL DEFAULT NULL,
file varchar(254) NOT NULL,
file varchar(254) NOT NULL,
mime_type varchar(150) NOT NULL,
menu_order int(11) NOT NULL DEFAULT '0',
featured tinyint(1) NULL DEFAULT '0',
is_approved tinyint(1) NULL DEFAULT '1',
metadata text NULL DEFAULT NULL,
type varchar(254) NULL DEFAULT 'post_images',
PRIMARY KEY (ID)
PRIMARY KEY (ID),
KEY post_id (post_id),
KEY type (type)
) $collate ; ";

// Table for storing custom sort fields
Expand All @@ -749,7 +751,7 @@ public static function get_schema() {
// Table for storing review info
/**
* UNIQUE KEY replaced to PRIMARY KEY to prevent database error:
* "Percona-XtraDB-Cluster prohibits use of DML command on a table without an explicit
* "Percona-XtraDB-Cluster prohibits use of DML command on a table without an explicit
* primary key with pxc_strict_mode = ENFORCING or MASTER"
*/
$tables .= " CREATE TABLE " . GEODIR_REVIEW_TABLE . " (
Expand All @@ -767,7 +769,7 @@ public static function get_schema() {
longitude varchar(22) DEFAULT '',
PRIMARY KEY (comment_id)
) $collate; ";

// Table to store api keys
$tables .= " CREATE TABLE " . GEODIR_API_KEYS_TABLE . " (
key_id BIGINT UNSIGNED NOT NULL auto_increment,
Expand Down Expand Up @@ -1130,7 +1132,7 @@ public static function db_cpt_default_columns( $cpt = array(), $post_type = '' )
$columns = array();

// Standard fields
$columns['post_id'] = "post_id int(11) NOT NULL";
$columns['post_id'] = "post_id bigint(20) NOT NULL";
$columns['post_title'] = "post_title text NULL DEFAULT NULL";
$columns['_search_title'] = "_search_title text NOT NULL";
$columns['post_status'] = "post_status varchar(20) NULL DEFAULT NULL";
Expand Down
7 changes: 4 additions & 3 deletions includes/admin/class-geodir-admin-setup-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public function setup_wizard_header() {

<div id="gd-setup-container" class="gd-setup wp-core-ui bg-whitex mx-auto mt-4x modal fade show overflow-auto" style="display: block;z-index: inherit;">

<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top shadow-sm <?php echo $aui_bs5 ? 'px-3' : '';?>">
<nav class="navbar navbar-expand-lg navbar-light bg-white sticky-top shadow-sm <?php echo $aui_bs5 ? 'px-3 py-2' : '';?>">
<a class="navbar-brand" href="#">
<h1 class="h5 p-0 m-0">
<i class="fas fa-globe-americas text-primary bg-white rounded-circle" style="color:#ff8333 !important;"></i>
Expand Down Expand Up @@ -369,12 +369,13 @@ public function setup_wizard_steps() {
<?php foreach ( $ouput_steps as $step_key => $step ) : ?>
<li class="nav-link border-0 d-flex align-content-center justify-content-center <?php
if ( $step_key === $this->step ) {
echo 'active ' . ( $aui_bs5 ? 'text-dark' : 'text-white' );
echo 'active ' . ( $aui_bs5 ? 'bg-primary text-white rounded fw-bold' : 'text-white' );
$tick_class = '';
} elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) {
$tick_class = 'text-primary';
echo $aui_bs5 ? 'bg-white rounded shadow-0 fw-bold' : '' ;
}else{
echo 'text-muted';
echo 'text-muted ' . ( $aui_bs5 ? 'bg-white rounded shadow-0 fw-bold' : '' );
}
?>"><span class="h5 p-0 m-0"><i class="fas fa-check-circle <?php echo $tick_class;?>"></i></span> <span class="pl-1 ps-1 align-self-center"><?php echo esc_html( $step['name'] ); ?></span>

Expand Down
4 changes: 2 additions & 2 deletions includes/class-geodir-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function register_rest_routes() {
if ( geodir_api_enabled() ) {
$gd_post_types = geodir_get_posttypes();

foreach ( $wp_post_types as $post_type ) {
foreach ( $wp_post_types as $post_type ) {
if ( ! in_array( $post_type->name, $gd_post_types ) ) {
continue;
}
Expand Down Expand Up @@ -264,7 +264,7 @@ public function setup_show_in_rest() {
$wp_post_types[$post_type]->show_in_rest = true;
$wp_post_types[$post_type]->rest_base = $data['has_archive'];
$wp_post_types[$post_type]->rest_controller_class = 'GeoDir_REST_Posts_Controller';

if ( ! empty( $data['taxonomies'] ) ) {
foreach ( $data['taxonomies'] as $taxonomy ) {
if ( isset( $wp_taxonomies[$taxonomy] ) ) {
Expand Down
21 changes: 21 additions & 0 deletions includes/class-geodir-post-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,27 @@ public static function schema( $post = '' ) {
$schema['priceRange'] = esc_attr( $gd_post->price_range );
}

// VacationRental
if ( 'VacationRental' === $schema_type ) {
$schema['identifier'] = absint( $gd_post->ID );

$accommodation = array();

$accommodation['@type'] = "Accommodation";

if ( ! empty( $gd_post->accommodates ) ) {
$accommodation['occupancy'] = array(
"@type"=> "QuantitativeValue",
"value" => esc_attr( $gd_post->accommodates ),

);
}

$schema['containsPlace'] = $accommodation;


}

/**
* Allow the schema JSON-LD info to be filtered.
*
Expand Down
5 changes: 3 additions & 2 deletions includes/general-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ function geodir_get_widget_listings( $query_args = array(), $count_only = false

$statuses = geodir_get_post_stati( $context, $query_args );


if ( count( $statuses ) > 1 ) {
$where = "AND {$wpdb->posts}.post_status IN( '" . implode( "', '", $statuses ) . "' )";
} else {
Expand Down Expand Up @@ -1078,7 +1079,7 @@ function geodir_get_widget_listings( $query_args = array(), $count_only = false
$where = apply_filters( 'geodir_filter_widget_listings_where', $where, $post_type );
$where = $where != '' ? " WHERE 1=1 " . $where : '';

$groupby = " GROUP BY $wpdb->posts.ID "; //@todo is this needed? faster without
$groupby = ""; //" GROUP BY $wpdb->posts.ID "; //@todo is this needed? faster without (commented out by stiofan 2024-02-16, if it breaks anything we can add it back here with a comment)
/**
* Filter widget listing groupby clause string part that is being used for query.
*
Expand Down Expand Up @@ -2958,4 +2959,4 @@ function geodir_cache_flush_group( $group ) {
}
}
}
}
}
24 changes: 12 additions & 12 deletions includes/post-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ function geodir_get_post_stati( $context, $args = array() ) {
$statuses = $publish_statuses;

if ( current_user_can( 'manage_options' ) ) {
$statuses[] = 'private';
//$statuses[] = 'private'; // i don't see how this is useful on the front end, it really slows the query down for admins doing testing (stiofan)
}
break;
case 'import':
Expand Down Expand Up @@ -1600,25 +1600,25 @@ function geodir_previous_next_post_join( $join, $in_same_term, $excluded_terms,
* @return string Filtered SQL WHERE clause.
*/
function geodir_previous_next_post_where( $where, $in_same_term, $excluded_terms, $taxonomy, $post ) {
global $wpdb, $plugin_prefix;
global $wpdb, $plugin_prefix, $gd_post;

if ( ! empty( $post->post_type ) && ( ! empty( $post->country_slug ) || ! empty( $post->region_slug ) || ! empty( $post->city_slug ) ) && in_array( $post->post_type, geodir_get_posttypes() ) ) {
if ( ! empty( $post->post_type ) && ( ! empty( $gd_post->country ) || ! empty( $gd_post->region ) || ! empty( $gd_post->city ) ) && in_array( $post->post_type, geodir_get_posttypes() ) ) {
$post_locations = '';
$post_locations_var = array();

if ( ! empty( $post->country_slug ) ) {
$post_locations .= " AND post_locations LIKE %s";
$post_locations_var[] = "%,[" . $post->country_slug . "]";
if ( ! empty( $gd_post->country ) ) {
$post_locations .= " AND gd.country = %s";
$post_locations_var[] = esc_attr( $gd_post->country );
}

if ( ! empty( $post->region_slug ) ) {
$post_locations .= " AND post_locations LIKE %s";
$post_locations_var[] = "%,[" . $post->region_slug . "],%";
if ( ! empty( $gd_post->region ) ) {
$post_locations .= " AND gd.region = %s";
$post_locations_var[] = esc_attr( $gd_post->region );
}

if ( ! empty( $post->city_slug ) ) {
$post_locations .= " AND post_locations LIKE %s";
$post_locations_var[] = "[" . $post->city_slug . "],%";
if ( ! empty( $gd_post->city ) ) {
$post_locations .= " AND gd.city = %s";
$post_locations_var[] = esc_attr( $gd_post->city );
}

$where .= $wpdb->prepare( $post_locations, $post_locations_var );
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ __WARNING: GDv2 is a significant update over GDv1 and may require manual work, s
= GeoDirectory v2.3.41 - TBD =
* OSM directions route should use listing location as an end point - CHANGED
* Skip TranslatePress plugin from Fast AJAX request - CHANGED
* Several SQL Query optimizations reducing some query times even further - ADDED
* GD > Single Next Prev not filtering by same location - FIXED
* Add listing zip and region discovery improvements - ADDED

= GeoDirectory v2.3.40 - 2024-02-15 =
* Custom single post map is not loading on non GD pages - FIXED
Expand Down
42 changes: 36 additions & 6 deletions templates/bootstrap/map/map-add-listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,27 @@ function geocodePosition(latLon, address) {
});
}

function geodirGetAnyZip(responses) {
var zip = '';

// Use a standard for loop instead of forEach
for (var j = 0; j < responses.length; j++) {
var response = responses[j];
console.log(response);
for (var i = 0; i < response.address_components.length; i++) {
var addr = response.address_components[i];
if (addr.types[0] == 'postal_code' && addr.short_name) {
return addr.short_name; // This will now return from geodirGetAnyZip
}
}
}

return zip; // This will only be reached if no postal_code is found
}

function geocodeResponse(responses) {
console.log(responses);//keep this for debugging
console.log(responses);//keep this for debugging
console.log('###');//keep this for debugging
if (responses && responses.length > 0) {
var getAddress = '';
var getAddress2 = '';
Expand Down Expand Up @@ -186,18 +205,20 @@ function geocodeResponse(responses) {
locality = addr;
}
if (addr.types[0] == 'premise') {
premise = addr;alert(4);
premise = addr;
}
if (addr.types[0] == 'establishment') {
establishment = addr;alert(5);
establishment = addr;
}
}
}
});

for (var i = 0; i < responses[0].address_components.length; i++) {
var addr = responses[0].address_components[i];
if (addr.types[0] == 'street_number') {


if (addr.types[0] == 'street_number') {
street_number = addr;
}
if (addr.types[0] == 'route') {
Expand Down Expand Up @@ -307,7 +328,16 @@ function geocodeResponse(responses) {
getAddress += route.long_name;//route
}

getZip = postal_code.long_name;//postal_code
getZip = postal_code.long_name;//postal_code

// maybe try and get zip alternative if region is missing so we can use our zip arrays to find the region later
if (!getState && !getZip) {
var zipFound = geodirGetAnyZip( responses );
if (zipFound) {
getZip = zipFound;
postal_code.long_name = getZip;
}
}

//getCountry
if (country.long_name) {
Expand Down Expand Up @@ -477,7 +507,7 @@ function geocodeResponse(responses) {
getCountry = "Holy See";
}

console.log(getAddress+', '+getCity+', '+getState+', '+getCountry);
console.log(getAddress+', '+getCity+', '+getState+', '+getCountry+', '+getZip);
<?php
/**
* Fires to add javascript variable to use in google map.
Expand Down

0 comments on commit b48ce7d

Please sign in to comment.