@@ -1528,7 +1528,7 @@ const escapedViewSegments = { "name": true, "segment": true, "height": true, "wi
15281528 * @returns {undefined } Returns nothing
15291529 */
15301530 async function getHeatmapNeo ( params ) {
1531- const result = { types : [ ] , data : [ ] } ;
1531+ const result = { types : [ ] , data : [ ] , domains : [ ] } ;
15321532
15331533 let device = { } ;
15341534 try {
@@ -1670,6 +1670,55 @@ const escapedViewSegments = { "name": true, "segment": true, "height": true, "wi
16701670 { $project : projectionQuery } ,
16711671 ] ;
16721672
1673+ const use_union_with = plugins . getConfig ( 'drill' , params . app_id && params . app && params . app . plugins , true ) . use_union_with ;
1674+
1675+ if ( use_union_with ) {
1676+ const oldCollectionName = 'drill_events' + crypto . createHash ( 'sha1' ) . update ( '[CLY]_action' + params . qstring . app_id ) . digest ( 'hex' ) ;
1677+ const eventHash = crypto . createHash ( 'sha1' ) . update ( '[CLY]_action' + params . qstring . app_id ) . digest ( 'hex' ) ;
1678+
1679+ const metaQuery = [
1680+ {
1681+ $facet : {
1682+ meta : [
1683+ { $match : { _id : 'meta' } } ,
1684+ { $project : { _id : 0 , 'sg.type' : 1 , 'sg.domain' : 1 } } ,
1685+ { $limit : 1 } ,
1686+ ] ,
1687+ meta_v2 : [
1688+ { $match : { _id : 'meta_v2' } } ,
1689+ { $project : { _id : 0 , 'sg.type' : 1 , 'sg.domain' : 1 } } ,
1690+ { $limit : 1 } ,
1691+ ] ,
1692+ } ,
1693+ } ,
1694+ ] ;
1695+
1696+ const metaKeys = [ 'meta' , 'meta_v2' ] ;
1697+ const metas = await common . drillDb . collection ( oldCollectionName ) . aggregate ( metaQuery ) . toArray ( ) ;
1698+ metaKeys . forEach ( ( key ) => {
1699+ if ( key in metas [ 0 ] ) {
1700+ const meta = metas [ 0 ] [ key ] [ 0 ] ;
1701+
1702+ if ( meta && meta . sg && meta . sg . type && meta . sg . type . values ) {
1703+ common . arrayAddUniq ( result . types , meta . sg . type . values ) ;
1704+ }
1705+
1706+ if ( meta && meta . sg && meta . sg . domain && meta . sg . domain . values ) {
1707+ common . arrayAddUniq ( result . domains , meta . sg . domain . values ) ;
1708+ }
1709+ }
1710+ } ) ;
1711+
1712+ const moreMeta = await common . drillDb . collection ( `drill_meta${ params . qstring . app_id } ` ) . findOne (
1713+ { _id : `meta_${ eventHash } ` } ,
1714+ { _id : 0 , 'sg.domain' : 1 } ,
1715+ ) ;
1716+
1717+ if ( moreMeta && moreMeta . sg && moreMeta . sg . domain ) {
1718+ common . arrayAddUniq ( result . domains , Object . keys ( moreMeta . sg . domain . values ) ) ;
1719+ }
1720+ }
1721+
16731722 try {
16741723 const data = await common . drillDb . collection ( 'drill_events' ) . aggregate ( aggregateQuery , { allowDiskUse : true } ) . toArray ( ) ;
16751724 result . data = data ;
0 commit comments