File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ -- fix "contacts.location" (was contacts.locations) --
2+ DROP FUNCTION IF EXISTS private .get_mining_stats (text );
3+
4+ CREATE FUNCTION private .get_mining_stats(mining_id text )
5+ RETURNS TABLE(
6+ user_id UUID,
7+ source text ,
8+ total_contacts_mined BIGINT ,
9+ total_reachable BIGINT ,
10+ total_with_phone BIGINT ,
11+ total_with_company BIGINT ,
12+ total_with_location BIGINT
13+ ) AS $$
14+ DECLARE
15+ user_id UUID;
16+ BEGIN
17+ -- Get the user_id first
18+ SELECT pt .user_id INTO user_id
19+ FROM private .tasks pt
20+ WHERE pt .details - >> ' miningId' = $1
21+ AND pt .status = ' done'
22+ ORDER BY pt .started_at DESC
23+ LIMIT 1 ;
24+
25+ -- Return the statistics
26+ RETURN QUERY
27+ SELECT
28+ user_id,
29+ (SELECT p .source FROM private .persons p WHERE p .mining_id = $1 LIMIT 1 ) AS source,
30+ COUNT (* ) AS total_contacts_mined,
31+ COUNT (* ) FILTER (WHERE contacts .status = ' VALID' ) AS total_reachable,
32+ COUNT (contacts .telephone ) AS total_with_phone,
33+ COUNT (* ) FILTER (WHERE contacts .job_title IS NOT NULL OR contacts .works_for IS NOT NULL ) AS total_with_company,
34+ COUNT (* ) FILTER (WHERE contacts .location IS NOT NULL AND contacts .location <> ' ' ) AS total_with_location
35+ FROM private .get_contacts_table (user_id) AS contacts
36+ WHERE contacts .mining_id = $1 ;
37+ END;
38+ $$ LANGUAGE plpgsql;
You can’t perform that action at this time.
0 commit comments