@@ -38,42 +38,28 @@ publish('requests', {
3838 } ,
3939 tags : [ 'crawl_complete' ]
4040} ) . preOps ( ctx => `
41- CREATE TEMP FUNCTION pruneHeaders(
42- jsonObject JSON
43- ) RETURNS JSON
44- LANGUAGE js AS '''
45- try {
46- for (const [key, value] of Object.entries(jsonObject)) {
47- if(key.startsWith('req_') || key.startsWith('resp_')) {
48- delete jsonObject[key]
49- }
50- }
51- return jsonObject
52- } catch (e) {
53- return jsonObject
54- }
55- ''';
41+ FOR client_value IN (SELECT * FROM UNNEST(['desktop', 'mobile']) AS client) DO
42+ FOR is_root_page_value IN (SELECT * FROM UNNEST([TRUE, FALSE]) AS is_root_page) DO
5643
57- DELETE FROM ${ ctx . self ( ) }
58- WHERE date = '${ constants . currentMonth } ' AND
59- client = 'desktop';
60- ` ) . query ( ctx => `
61- SELECT
62- *
63- FROM ${ ctx . ref ( 'crawl_staging' , 'requests' ) }
64- WHERE date = '${ constants . currentMonth } ' AND
65- client = 'desktop'
66- ${ constants . devRankFilter }
67- ` ) . postOps ( ctx => `
68- DELETE FROM ${ ctx . self ( ) }
69- WHERE date = '${ constants . currentMonth } ' AND
70- client = 'mobile';
44+ -- Delete old entries
45+ DELETE FROM ${ ctx . self ( ) }
46+ WHERE date = '${ constants . currentMonth } '
47+ AND client = client_value.client
48+ AND is_root_page = is_root_page_value.is_root_page;
7149
72- INSERT INTO ${ ctx . self ( ) }
73- SELECT
74- *
50+ -- Insert new entries
51+ INSERT INTO ${ ctx . self ( ) }
52+ SELECT *
53+ FROM ${ ctx . ref ( 'crawl_staging' , 'requests' ) }
54+ WHERE date = '${ constants . currentMonth } ' AND
55+ client = client_value.client AND
56+ is_root_page = is_root_page_value.is_root_page ${ constants . devRankFilter } ;
57+
58+ END FOR;
59+ END FOR;
60+ ` ) . query ( ctx => `
61+ SELECT *
7562FROM ${ ctx . ref ( 'crawl_staging' , 'requests' ) }
76- WHERE date = '${ constants . currentMonth } ' AND
77- client = 'mobile'
78- ${ constants . devRankFilter }
63+ WHERE date IS NULL ${ constants . devRankFilter }
64+ LIMIT 0
7965` )
0 commit comments