-
-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathlcp_lazy_wordpress.sql
More file actions
61 lines (56 loc) · 1.66 KB
/
lcp_lazy_wordpress.sql
File metadata and controls
61 lines (56 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
CREATE TEMP FUNCTION getLoadingAttr(attributes STRING) RETURNS STRING LANGUAGE js AS '''
try {
const data = JSON.parse(attributes);
const loadingAttr = data.find(attr => attr["name"] === "loading")
return loadingAttr.value
} catch (e) {
return "";
}
''';
CREATE TEMP FUNCTION hasLazyHeuristics(attributes STRING) RETURNS BOOLEAN LANGUAGE js AS '''
try {
const data = JSON.parse(attributes);
const classes = data.find(attr => attr["name"] === "class").value;
const hasLazyClasses = classes.indexOf('lazyload') !== -1;
const hasLazySrc = data.includes(attr => attr["name"] === "data-src");
return hasLazyClasses || hasLazySrc;
} catch (e) {
return false;
}
''';
WITH lazy AS (
SELECT
_TABLE_SUFFIX AS client,
url,
getLoadingAttr(JSON_EXTRACT(payload, '$._performance.lcp_elem_stats.attributes')) = 'lazy' AS native_lazy,
hasLazyHeuristics(JSON_EXTRACT(payload, '$._performance.lcp_elem_stats.attributes')) AS custom_lazy
FROM
`httparchive.pages.2022_06_01_*`
WHERE
# <img> LCP only.
JSON_EXTRACT_SCALAR(payload, '$._performance.lcp_elem_stats.nodeName') = 'IMG'
),
wp AS (
SELECT DISTINCT
_TABLE_SUFFIX AS client,
url,
TRUE AS wordpress
FROM
`httparchive.technologies.2022_06_01_*`
WHERE
app = 'WordPress'
)
SELECT
client,
COUNTIF(wordpress) AS wordpress,
COUNTIF(native_lazy) AS native_lazy,
COUNTIF(custom_lazy) AS custom_lazy,
COUNTIF(wordpress AND native_lazy) / COUNTIF(native_lazy) AS pct_wordpress_native_lazy,
COUNTIF(wordpress AND custom_lazy) / COUNTIF(custom_lazy) AS pct_wordpress_custom_lazy
FROM
lazy
LEFT JOIN
wp
USING (client, url)
GROUP BY
client