我们使用WP作为业务目录的后端。我有一个插件,可以根据位置坐标进行查询,查找与给定“列表”最近的10个位置。这个查询非常慢(平均1.5-2秒),但它确实是非常有价值和重要的信息。在我开始为解决方案编码之前,我想我会在这里抛出这个问题,看看你会建议如何处理它。
可以在此处找到示例页Dev Server Listing 您将在底部看到标记为“附近帖子”的问题结果。此列表是使用GEO Mashup生成的Plugin
在本例中,以下是运行的查询:
SELECT
gmlr.object_id,
gmlr.geo_date,
o.post_title AS label,
gml.*,
o.post_author,
wp_geo_mashup_locations.lat,
wp_geo_mashup_locations.lng,
wp_geo_mashup_locations.address,
wp_geo_mashup_locations.saved_name,
wp_geo_mashup_locations.postal_code,
wp_geo_mashup_locations.admin_code,
wp_geo_mashup_locations.sub_admin_code,
wp_geo_mashup_locations.country_code,
wp_geo_mashup_locations.locality_name,
6371 * 2 * ASIN(
SQRT(
POWER(
SIN(
RADIANS(42.0396996 - wp_geo_mashup_locations.lat) / 2
),
2
)
+ COS(
RADIANS(42.0396996)
)
* COS(
RADIANS(wp_geo_mashup_locations.lat)
) * POWER(
SIN(
RADIANS(-71.2824554 - wp_geo_mashup_locations.lng)
/ 2
),
2
)
)
) AS distance_km
FROM wp_geo_mashup_locations gml INNER JOIN
wp_geo_mashup_location_relationships gmlr
ON gmlr.object_name = \'post\' AND gmlr.location_id = gml.id
INNER JOIN wp_posts o ON o.ID = gmlr.object_id
INNER JOIN wp_geo_mashup_location_relationships
ON wp_geo_mashup_location_relationships.object_id = o.ID
INNER JOIN wp_geo_mashup_locations
ON wp_geo_mashup_locations.id = wp_geo_mashup_location_relationships.location_id
WHERE post_status = \'publish\'
AND o.post_type IN (\'listing\', \'post\', \'page\', \'attachment\', \'product\', \'transaction\')
AND gmlr.object_id NOT IN (7251) AND (
wp_geo_mashup_location_relationships.object_name = \'post\' AND
wp_geo_mashup_locations.lat > 41.314769646 AND
wp_geo_mashup_locations.lng > -72.2585540753 AND
wp_geo_mashup_locations.lat < 42.764629554 AND
wp_geo_mashup_locations.lng < -70.3063567247)
GROUP BY o.ID
HAVING distance_km < 80.4672248946
ORDER BY distance_km ASC
LIMIT 0, 10
/* From path/to/request/uri/ in
[/wp-content/plugins/geo-mashup/geo-mashup-db.php:1670] */
CALL FROM :REQUIRE(\'wp-blog-header.php\'),
require_once(\'wp-includes/template-loader.php\'),
include(\'/themes/vantage/wrapper.php\'),
load_template,
require_once(\'/themes/vantage/single-listing.php\'),
GeoMashup::nearby_list,
GeoMashupSearch->__construct,
GeoMashupSearch-> QUERY,
GeoMashupDB::get_object_locations
感谢您的任何想法、建议或指导。我们如何加快速度?