simplemap icon indicating copy to clipboard operation
simplemap copied to clipboard

MySQL error on distance field when blitz refreshes page cache

Open jripmeester opened this issue 5 years ago • 0 comments

Description

When caching plugin Blitz refreshes it's caches (when an entry has been edited). And a specific page in the refresh queue has entries sorted on distances on the page. The page generation fails with a distance field related error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'order clause' The SQL being executed was: SELECT elements.id FROM (SELECT elements.id AS elementsId, elements_sites.id AS elementsSitesId, content.id AS contentId, structureelements.structureId FROM elements elements INNER JOIN entries entries ON entries.id = elements.id INNER JOIN elements_sites elements_sites ON elements_sites.elementId = elements.id INNER JOIN content content ON (content.elementId = elements.id) AND (content.siteId = elements_sites.siteId) LEFT JOIN structureelements structureelements ON (structureelements.elementId = elements.id) AND (EXISTS (SELECT * FROM structures WHERE (id = structureelements.structureId) AND (dateDeleted IS NULL))) WHERE (entries.sectionId=5) AND (elements_sites.siteId=2) AND (elements.id != '4654') AND (elements.archived=FALSE) AND (((elements.enabled=TRUE) AND (elements_sites.enabled=TRUE)) AND (entries.postDate <= '2020-12-10 15:56:00') AND ((entries.expiryDate IS NULL) OR (entries.expiryDate > '2020-12-10 15:56:00'))) AND (elements.dateDeleted IS NULL) AND (elements.draftId IS NULL) AND (elements.revisionId IS NULL) ORDER BY distance LIMIT 6) subquery INNER JOIN entries entries ON entries.id = subquery.elementsId INNER JOIN elements elements ON elements.id = subquery.elementsId INNER JOIN elements_sites elements_sites ON elements_sites.id = subquery.elementsSitesId INNER JOIN content content ON content.id = subquery.contentId LEFT JOIN structureelements structureelements ON (structureelements.elementId = subquery.elementsId) AND (structureelements.structureId = subquery.structureId) ORDER BY distance

This is the entry query on this specific page: {% set nearByLocations = craft.entries.section('location').locationData({ location: { lat: entry.locationData.lat, lng: entry.locationData.lng }, radius: 500, unit: 'm', }).limit(6).id('not '~entry.id).orderBy('distance').all() %}

This error will only occur when run through a queue job. Visiting the page directly does not give this MySQL error. Due to this error we now need to refresh the cache manually on daily base.

Steps to reproduce

  1. Install Craft with Blitz and Maps plugin 2.Create section with map field
  2. Activate Blitz caching
  3. cache a entry page with a nearby locations query on it
  4. Edit the entry so Blitz cache refresh is triggered to run through the queue.

Additional info

  • Craft version: 3.5.12.1
  • Maps version: 3.8.4.1 (Lite)
  • PHP version: 7.4.13
  • Database driver & version: MySQL 5.5.5
  • Other Plugins: Blitz 3.6.10

jripmeester avatar Dec 11 '20 07:12 jripmeester