|
| 1 | +import { db, event, graphqlQuery } from "#src/utils"; |
| 2 | + |
| 3 | +interface ItemCount { |
| 4 | + key: string; |
| 5 | + count: number; |
| 6 | +} |
| 7 | + |
| 8 | +interface AuditSummaryResp { |
| 9 | + unique_url_stats: { |
| 10 | + aggregate: { |
| 11 | + count: number; |
| 12 | + }; |
| 13 | + }; |
| 14 | + mostCommonUrls: ItemCount[]; |
| 15 | + mostCommonBlockers: ItemCount[]; |
| 16 | + mostCommonTags: ItemCount[]; |
| 17 | +} |
| 18 | + |
| 19 | +export const getAuditSummaryFast = async () => { |
| 20 | + |
| 21 | + const start = performance.now(); |
| 22 | + const auditId = (event.queryStringParameters as any).id; |
| 23 | + const mostCommonUrlsLimit = |
| 24 | + (event.queryStringParameters as any).mostCommonUrlsLimit ?? 5; |
| 25 | + const mostCommonBlockersLimit = |
| 26 | + (event.queryStringParameters as any).mostCommonBlockersLimit ?? 5; |
| 27 | + /* const mostCommonCategoriesLimit = |
| 28 | + (event.queryStringParameters as any).mostCommonCategoriesLimit ?? 3; |
| 29 | + */ |
| 30 | + const mostCommonTagsLimit = |
| 31 | + (event.queryStringParameters as any).mostCommonTagsLimit ?? 3; |
| 32 | + |
| 33 | + const query = { |
| 34 | + query: `query GetFullAuditSummary( |
| 35 | + $audit_id: uuid!, |
| 36 | + $urlLimit: Int, |
| 37 | + $msgLimit: Int, |
| 38 | + $tagLimit: Int |
| 39 | +) { |
| 40 | + # 1. Total Unique URLs with blockers |
| 41 | + unique_url_stats: blocker_summary_view_aggregate( |
| 42 | + where: { audit_id: { _eq: $audit_id } } |
| 43 | + ) { |
| 44 | + aggregate { |
| 45 | + count(columns: url, distinct: true) |
| 46 | + } |
| 47 | + } |
| 48 | +
|
| 49 | + mostCommonUrls: get_most_common_urls( |
| 50 | + args: { search_audit_id: $audit_id, row_limit: $urlLimit } |
| 51 | + ) { |
| 52 | + key |
| 53 | + count |
| 54 | + } |
| 55 | +
|
| 56 | + mostCommonBlockers: get_most_common_messages( |
| 57 | + args: { search_audit_id: $audit_id, row_limit: $msgLimit } |
| 58 | + ) { |
| 59 | + key |
| 60 | + count |
| 61 | + } |
| 62 | +
|
| 63 | + mostCommonTags: get_most_common_tags( |
| 64 | + args: { search_audit_id: $audit_id, row_limit: $tagLimit } |
| 65 | + ) { |
| 66 | + key |
| 67 | + count |
| 68 | + } |
| 69 | +}`, |
| 70 | + variables: { |
| 71 | + audit_id: auditId, |
| 72 | + urlLimit: mostCommonUrlsLimit, |
| 73 | + msgLimit: mostCommonBlockersLimit, |
| 74 | + tagLimit: mostCommonTagsLimit |
| 75 | + }, |
| 76 | + }; |
| 77 | + const response = (await graphqlQuery(query)) as AuditSummaryResp; |
| 78 | + |
| 79 | + const end = performance.now(); |
| 80 | + return { |
| 81 | + statusCode: 200, |
| 82 | + headers: { "content-type": "application/json" }, |
| 83 | + body: { |
| 84 | + urlsWithBlockersCount: response.unique_url_stats.aggregate.count, |
| 85 | + urlsWithMostErrors: response.mostCommonUrls, |
| 86 | + mostCommonErrors: response.mostCommonBlockers, |
| 87 | + mostCommonTags: response.mostCommonTags, |
| 88 | + executionTime: end - start |
| 89 | + }, |
| 90 | + }; |
| 91 | +}; |
0 commit comments