1 (edited by namwebs 28-02-2024 10:23:04)

Topic: work_queue table errors

Hi,

Every time a user edits an obs which is part of a sample, I get an error added to the work_queue table even if the edit is saved correctly. The task is task_spatial_index_builder_sample. It seems like the empty location_types array is causing a problem.

There was an SQL error: ERROR:  syntax error at or near ")"
LINE 16:     AND l.location_type_id IN ()
                                        ^ - DROP TABLE IF EXISTS smplist;
DROP TABLE IF EXISTS changed_samples;
SELECT record_id INTO temporary smplist
FROM work_queue
WHERE claimed_by='65deff94d3b293.35621103'
AND entity='sample'
AND task='task_spatial_index_builder_sample';

WITH RECURSIVE ltree AS (
  SELECT l.id, l.location_type_id, l.parent_id, s.id as sample_id
  FROM smplist sl
  JOIN cache_samples_functional s ON s.id=sl.record_id
    LEFT JOIN locations l ON st_intersects(l.boundary_geom, s.public_geom)
    AND (st_geometrytype(s.public_geom)='ST_Point' OR NOT st_touches(l.boundary_geom, s.public_geom))
    AND l.deleted=false
    AND l.location_type_id IN ()
    
    /* type filters, e.g. and (l.location_type_id<>#id or s.survey_id in (#surveys)) */
  UNION ALL
  SELECT l.id, ltree.location_type_id, l.parent_id, ltree.sample_id
  FROM locations l
  JOIN ltree ON ltree.parent_id = l.id
  AND ltree.location_type_id IN ()
)
SELECT sample_id, array_agg(distinct id) as location_ids
INTO TEMPORARY changed_samples
FROM ltree
GROUP BY sample_id;

-- Samples - for updated samples, copy over the changes if there are any
UPDATE cache_samples_functional u
  SET location_ids=cs.location_ids
FROM changed_samples cs
WHERE cs.sample_id=u.id
AND (
  ((u.location_ids IS NULL)<>(cs.location_ids IS NULL))
  OR u.location_ids <@ cs.location_ids = false OR u.location_ids @> cs.location_ids = false
);

UPDATE cache_occurrences_functional o
SET location_ids = s.location_ids
FROM cache_samples_functional s
JOIN changed_samples cs on cs.sample_id=s.id
WHERE o.sample_id=s.id
AND (o.location_ids <> s.location_ids OR (o.location_ids IS NULL)<>(s.location_ids IS NULL));

In the spatial_index_builder.php this (default) code is present. I've tried removing it but that just causes other errors. Does it need to change somehow so there is something in the location_types array?:

// List the location type terms that area available for indexing against. Typically these will need to be those
// which are frequently reported against especially where the boundaries are large and/or complex.
$config['location_types']=array(
  'Vice County',
  'Local wildlife site'
);

// Of the indexed types, which are layers which have a parent ID that points to
// another higher level layer that should also be indexed?
$config['hierarchical_location_types']=array(
  'Vice County',
);

// If any of the indexed location types only need indexing for certain surveys then that can be configured here.
// Omit this configuration if not required.
// $config['survey_restrictions']=array(
// 'Local wildlife site' => array(25, 26, 27) // only build an index for surveys 25, 26 and 27 for local wildlife sites
//);

Apart from anything else, if the work_queue table has entries, other things in the warehouse seem to stop working (such as filtering occurrences). Once I clear it, these issues disappear.

Any ideas?