Skip to content

Commit

Permalink
add cdrs doc id to view keys to avoid pagination problem (2600hz#5491)
Browse files Browse the repository at this point in the history
  • Loading branch information
icehess authored and k-anderson committed Feb 6, 2019
1 parent c6a11e2 commit 0246d70
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 4 deletions.
6 changes: 5 additions & 1 deletion applications/crossbar/src/modules/cb_cdrs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ fix_filter_call_id(CallId) ->
load_cdr_summary(Context) ->
lager:debug("loading cdr summary for account ~s", [cb_context:account_id(Context)]),
Options = [{'mapper', fun normalize_summary_results/2}
,{'range_start_keymap', []}
,{'range_end_keymap', crossbar_view:suffix_key_fun([kz_json:new()])}
,{'list', ?CB_SUMMARY_LIST}
],
C1 = crossbar_view:load_modb(Context, ?CB_SUMMARY_VIEW, Options),
Expand Down Expand Up @@ -329,13 +331,15 @@ normalize_summary_results(JObj, Acc) -> [JObj|Acc].
get_view_options([{<<"cdrs">>, []}, {?KZ_ACCOUNTS_DB, _}|_]) ->
{?CB_LIST
,[{'mapper', fun cdrs_listing_mapper/3}
,{'range_start_keymap', []}
,{'range_end_keymap', crossbar_view:suffix_key_fun([kz_json:new()])}
,'include_docs'
]
};
get_view_options([{<<"cdrs">>, []}, {<<"users">>, [OwnerId]}|_]) ->
{?CB_LIST_BY_USER
,[{'range_start_keymap', [OwnerId]}
,{'range_end_keymap', [OwnerId]}
,{'range_end_keymap', fun(Ts) -> [OwnerId, Ts, kz_json:new()] end}
,{'mapper', fun cdrs_listing_mapper/3}
,'include_docs'
]
Expand Down
92 changes: 89 additions & 3 deletions core/kazoo_modb/priv/couchdb/views/cdrs.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,99 @@
},
"views": {
"crossbar_listing": {
"map": "function(doc) {if (doc.pvt_deleted || doc.pvt_type != 'cdr') return;emit(doc.pvt_created, {id: doc._id,call_id: doc.call_id,caller_id_name: doc.caller_id_name,caller_id_number: doc.caller_id_number,callee_id_name: doc.callee_id_name,callee_id_number: doc.callee_id_number,duration_seconds: doc.duration_seconds,billing_seconds: doc.billing_seconds,timestamp: doc.timestamp,hangup_cause: doc.hangup_cause,other_leg_call_id: doc.other_leg_call_id,owner_id: doc.custom_channel_vars.owner_id,to: doc.to_uri,from: doc.from_uri,inception: doc.custom_channel_vars.inception,direction: doc.call_direction,request: doc.request,authorizing_id: doc.custom_channel_vars.authorizing_id,media_recordings: doc.custom_channel_vars.media_recordings});}"
"map": [
"function(doc) {",
" if (doc.pvt_deleted || doc.pvt_type != 'cdr') return;",
" emit([doc.pvt_created, doc._id], {",
" id: doc._id,",
" call_id: doc.call_id,",
" caller_id_name: doc.caller_id_name,",
" caller_id_number: doc.caller_id_number,",
" callee_id_name: doc.callee_id_name,",
" callee_id_number: doc.callee_id_number,",
" duration_seconds: doc.duration_seconds,",
" billing_seconds: doc.billing_seconds,",
" timestamp: doc.timestamp,",
" hangup_cause: doc.hangup_cause,",
" other_leg_call_id: doc.other_leg_call_id,",
" owner_id: doc.custom_channel_vars.owner_id,",
" to: doc.to_uri,",
" from: doc.from_uri,",
" inception: doc.custom_channel_vars.inception,",
" direction: doc.call_direction,",
" request: doc.request,",
" authorizing_id: doc.custom_channel_vars.authorizing_id,",
" media_recordings: doc.custom_channel_vars.media_recordings",
" });",
"}"
]
},
"listing_by_owner": {
"map": "function(doc) { if(doc.pvt_type != 'cdr' || doc.pvt_deleted || !doc.custom_channel_vars || !doc.custom_channel_vars.owner_id) return; emit([doc.custom_channel_vars.owner_id, doc.pvt_created], {'id':doc._id, 'call_id': doc.call_id, 'caller_id_name': doc.caller_id_name, 'caller_id_number': doc.caller_id_number, 'callee_id_name': doc.callee_id_name, 'callee_id_number': doc.callee_id_number, 'duration_seconds': doc.duration_seconds, 'billing_seconds': doc.billing_seconds, 'timestamp': doc.timestamp, 'hangup_cause':doc.hangup_cause, 'other_leg_call_id':doc.other_leg_call_id, 'call_direction':doc.call_direction, 'to': doc.to_uri, 'from': doc.from_uri, 'inception':doc.custom_channel_vars.inception})}"
"map": [
"function(doc) {",
" if (doc.pvt_type != 'cdr' || doc.pvt_deleted || !doc.custom_channel_vars || !doc.custom_channel_vars.owner_id) return;",
" emit([doc.custom_channel_vars.owner_id, doc.pvt_created, doc._id], {",
" 'id': doc._id,",
" 'call_id': doc.call_id,",
" 'caller_id_name': doc.caller_id_name,",
" 'caller_id_number': doc.caller_id_number,",
" 'callee_id_name': doc.callee_id_name,",
" 'callee_id_number': doc.callee_id_number,",
" 'duration_seconds': doc.duration_seconds,",
" 'billing_seconds': doc.billing_seconds,",
" 'timestamp': doc.timestamp,",
" 'hangup_cause': doc.hangup_cause,",
" 'other_leg_call_id': doc.other_leg_call_id,",
" 'call_direction': doc.call_direction,",
" 'to': doc.to_uri,",
" 'from': doc.from_uri,",
" 'inception': doc.custom_channel_vars.inception",
" })",
"}"
]
},
"summarize_cdrs": {
"map": "function(doc) { if(doc.pvt_type != 'cdr' || doc.pvt_deleted || !doc.custom_channel_vars || doc.channel_name.indexOf(\"loopback\") !== -1 || (doc.call_direction == 'inbound' && doc.custom_channel_vars.authorizing_id) || (doc.call_direction == 'outbound' && !doc.custom_channel_vars.resource_id)) return; if (doc.call_direction == 'inbound') { var domain = doc.from.substr(doc.from.indexOf(\"@\") + 1); } else { var domain = doc.to.substr(doc.to.indexOf(\"@\") + 1); } var number = doc.to.substr(0, doc.to.indexOf('@')); if (number.match(/^\\+1((?:800|888|877|866|855)\\d{7})$/)) { var classifier = 'tollfree_us'; } else if (number.match(/^\\+1(900\\d{7})$/)) { var classifier = 'toll_us'; } else if (number.match(/^(911|933)$/)) { var classifier = 'emergency'; } else if (number.match(/^\\+?1((?:684|264|268|242|246|441|284|345|767|809|829|849|473|671|876|664|670|787|939|869|758|784|721|868|649|340)\\d{7})$/)) { var classifier = 'caribbean'; } else if (number.match(/^\\+?1?([2-9][0-9]{2}[2-9][0-9]{6})$/)) { var classifier = 'did_us'; } else if (number.match(/^\\+[2-9]\\d{7,}$/)) { var classifier = 'international'; } else { var classifier = 'unknown'; } if (doc.custom_channel_vars.rate_name) { emit (doc.pvt_created, {'direction': doc.call_direction, 'classifier': classifier, 'domain': domain, 'billable_seconds': parseInt(doc.billing_seconds), 'rate_name': doc.custom_channel_vars.rate_name}); } else { emit (doc.pvt_created, {'direction': doc.call_direction, 'classifier': classifier, 'domain': domain, 'billable_seconds': parseInt(doc.billing_seconds)}); }}"
"map": [
"function(doc) {",
" if (doc.pvt_type != 'cdr' || doc.pvt_deleted || !doc.custom_channel_vars || doc.channel_name.indexOf('loopback') !== -1 || (doc.call_direction == 'inbound' && doc.custom_channel_vars.authorizing_id) || (doc.call_direction == 'outbound' && !doc.custom_channel_vars.resource_id)) return;",
" if (doc.call_direction == 'inbound') {",
" var domain = doc.from.substr(doc.from.indexOf('@') + 1);",
" } else {",
" var domain = doc.to.substr(doc.to.indexOf('@') + 1);",
" }",
" var number = doc.to.substr(0, doc.to.indexOf('@'));",
" if (number.match(/^\\+1((?:800|888|877|866|855)\\d{7})$/)) {",
" var classifier = 'tollfree_us';",
" } else if (number.match(/^\\+1(900\\d{7})$/)) {",
" var classifier = 'toll_us';",
" } else if (number.match(/^(911|933)$/)) {",
" var classifier = 'emergency';",
" } else if (number.match(/^\\+?1((?:684|264|268|242|246|441|284|345|767|809|829|849|473|671|876|664|670|787|939|869|758|784|721|868|649|340)\\d{7})$/)) {",
" var classifier = 'caribbean';",
" } else if (number.match(/^\\+?1?([2-9][0-9]{2}[2-9][0-9]{6})$/)) {",
" var classifier = 'did_us';",
" } else if (number.match(/^\\+[2-9]\\d{7,}$/)) {",
" var classifier = 'international';",
" } else {",
" var classifier = 'unknown';",
" } if (doc.custom_channel_vars.rate_name) {",
" emit([doc.pvt_created, doc._id], {",
" 'direction': doc.call_direction,",
" 'classifier': classifier,",
" 'domain': domain,",
" 'billable_seconds': parseInt(doc.billing_seconds),",
" 'rate_name': doc.custom_channel_vars.rate_name",
" });",
" } else {",
" emit([doc.pvt_created, doc._id], {",
" 'direction': doc.call_direction,",
" 'classifier': classifier,",
" 'domain': domain,",
" 'billable_seconds': parseInt(doc.billing_seconds)",
" });",
" }",
"}"
]
}
}
}

0 comments on commit 0246d70

Please sign in to comment.