@@ -145,96 +145,6 @@ def create_dashboard_schema(cursor, username: str) -> None:
145
145
)
146
146
147
147
148
- def create_collection_search_functions (cursor ) -> None :
149
- """Create custom functions for collection-level search."""
150
-
151
- search_collection_ids_sql = """
152
- CREATE OR REPLACE FUNCTION pgstac.collection_id_search(_search jsonb = '{}'::jsonb) RETURNS SETOF text AS $$
153
- DECLARE
154
- searches searches%ROWTYPE;
155
- _where text;
156
- token_where text;
157
- full_where text;
158
- orderby text;
159
- query text;
160
- token_type text := substr(_search->>'token',1,4);
161
- curs refcursor;
162
- iter_record items%ROWTYPE;
163
- prev_query text;
164
- next text;
165
- prev_id text;
166
- has_next boolean := false;
167
- has_prev boolean := false;
168
- prev text;
169
- total_count bigint;
170
- context jsonb;
171
- includes text[];
172
- excludes text[];
173
- exit_flag boolean := FALSE;
174
- batches int := 0;
175
- timer timestamptz := clock_timestamp();
176
- pstart timestamptz;
177
- pend timestamptz;
178
- pcurs refcursor;
179
- search_where search_wheres%ROWTYPE;
180
- id text;
181
- collections text[];
182
- BEGIN
183
- CREATE TEMP TABLE results (collection text, content jsonb) ON COMMIT DROP;
184
- -- if ids is set, short circuit and just use direct ids query for each id
185
- -- skip any paging or caching
186
- -- hard codes ordering in the same order as the array of ids
187
- searches := search_query(_search);
188
- _where := searches._where;
189
- orderby := searches.orderby;
190
- search_where := where_stats(_where);
191
- total_count := coalesce(search_where.total_count, search_where.estimated_count);
192
-
193
- IF token_type='prev' THEN
194
- token_where := get_token_filter(_search, null::jsonb);
195
- orderby := sort_sqlorderby(_search, TRUE);
196
- END IF;
197
- IF token_type='next' THEN
198
- token_where := get_token_filter(_search, null::jsonb);
199
- END IF;
200
-
201
- full_where := concat_ws(' AND ', _where, token_where);
202
- RAISE NOTICE 'FULL QUERY % %', full_where, clock_timestamp()-timer;
203
- timer := clock_timestamp();
204
-
205
- FOR query IN SELECT partition_queries(full_where, orderby, search_where.partitions)
206
- LOOP
207
- timer := clock_timestamp();
208
- RAISE NOTICE 'Partition Query: %', query;
209
- batches := batches + 1;
210
- -- curs = create_cursor(query);
211
- RAISE NOTICE 'cursor_tuple_fraction: %', current_setting('cursor_tuple_fraction');
212
- OPEN curs FOR EXECUTE query;
213
- LOOP
214
- FETCH curs into iter_record;
215
- EXIT WHEN NOT FOUND;
216
-
217
- INSERT INTO results (collection, content) VALUES (iter_record.collection, iter_record.content);
218
-
219
- END LOOP;
220
- CLOSE curs;
221
- RAISE NOTICE 'Query took %.', clock_timestamp()-timer;
222
- timer := clock_timestamp();
223
- EXIT WHEN exit_flag;
224
- END LOOP;
225
- RAISE NOTICE 'Scanned through % partitions.', batches;
226
-
227
- RETURN QUERY SELECT DISTINCT collection FROM results WHERE content is not NULL;
228
-
229
- DROP TABLE results;
230
-
231
- RETURN;
232
- END;
233
- $$ LANGUAGE PLPGSQL SECURITY DEFINER SET SEARCH_PATH TO pgstac, public SET cursor_tuple_fraction TO 1;
234
- """
235
- cursor .execute (sql .SQL (search_collection_ids_sql ))
236
-
237
-
238
148
def create_collection_extents_functions (cursor ) -> None :
239
149
"""
240
150
Functions to update spatial and temporal extents off all items in a collection
@@ -451,12 +361,7 @@ def handler(event, context):
451
361
)
452
362
)
453
363
454
- # As admin, create custom search functions
455
- with psycopg .connect (stac_db_conninfo , autocommit = True ) as conn :
456
- with conn .cursor () as cur :
457
- print ("Creating custom STAC search functions..." )
458
- create_collection_search_functions (cursor = cur )
459
-
364
+ # As admin, create custom dashboard functions
460
365
with psycopg .connect (stac_db_conninfo , autocommit = True ) as conn :
461
366
with conn .cursor () as cur :
462
367
print ("Creating dashboard schema..." )
0 commit comments