@@ -30,11 +30,6 @@ use tokio_util::io::ReaderStream;
3030use tracing:: warn;
3131use urlencoding:: encode;
3232
33- const BILLING_STATUS_CHARGED : & str = "charged" ;
34- const BILLING_STATUS_INCLUDED : & str = "included" ;
35- const BILLING_STATUS_ZERO_DURATION : & str = "zero-duration" ;
36- const BILLING_STATUS_UNRATED : & str = "unrated" ;
37-
3833use crate :: models:: {
3934 call_record:: {
4035 ActiveModel as CallRecordActiveModel , Column as CallRecordColumn ,
@@ -1000,13 +995,6 @@ async fn load_filters(db: &DatabaseConnection) -> Result<Value, DbErr> {
1000995 "departments" : departments,
1001996 "sip_trunks" : sip_trunks,
1002997 "tags" : [ ] ,
1003- "billing_status" : [
1004- "any" ,
1005- BILLING_STATUS_CHARGED ,
1006- BILLING_STATUS_INCLUDED ,
1007- BILLING_STATUS_ZERO_DURATION ,
1008- BILLING_STATUS_UNRATED ,
1009- ] ,
1010998 } ) )
1011999}
10121000
@@ -1017,16 +1005,11 @@ fn build_condition(filters: &Option<QueryCallRecordFilters>) -> Condition {
10171005 if let Some ( q_raw) = filters. q . as_ref ( ) {
10181006 let trimmed = q_raw. trim ( ) ;
10191007 if !trimmed. is_empty ( ) {
1020- let mut any_match = Condition :: any ( ) ;
1021- any_match = any_match. add ( CallRecordColumn :: CallId . contains ( trimmed) ) ;
1022- any_match = any_match. add ( CallRecordColumn :: DisplayId . contains ( trimmed) ) ;
1023- any_match = any_match. add ( CallRecordColumn :: FromNumber . contains ( trimmed) ) ;
1024- any_match = any_match. add ( CallRecordColumn :: ToNumber . contains ( trimmed) ) ;
1025- any_match = any_match. add ( CallRecordColumn :: CallerName . contains ( trimmed) ) ;
1026- any_match = any_match. add ( CallRecordColumn :: AgentName . contains ( trimmed) ) ;
1027- any_match = any_match. add ( CallRecordColumn :: Queue . contains ( trimmed) ) ;
1028- any_match = any_match. add ( CallRecordColumn :: SipGateway . contains ( trimmed) ) ;
1029- condition = condition. add ( any_match) ;
1008+ let mut q_condition = Condition :: any ( ) ;
1009+ q_condition = q_condition. add ( CallRecordColumn :: CallId . eq ( trimmed) ) ;
1010+ q_condition = q_condition. add ( CallRecordColumn :: ToNumber . eq ( trimmed) ) ;
1011+ q_condition = q_condition. add ( CallRecordColumn :: FromNumber . eq ( trimmed) ) ;
1012+ condition = condition. add ( q_condition) ;
10301013 }
10311014 }
10321015
@@ -1045,10 +1028,18 @@ fn build_condition(filters: &Option<QueryCallRecordFilters>) -> Condition {
10451028 }
10461029 }
10471030
1048- if let Some ( from) = parse_date ( filters. date_from . as_ref ( ) , false ) {
1031+ let date_from = parse_date ( filters. date_from . as_ref ( ) , false ) ;
1032+ let date_to = parse_date ( filters. date_to . as_ref ( ) , true ) ;
1033+
1034+ if let Some ( from) = date_from {
10491035 condition = condition. add ( CallRecordColumn :: StartedAt . gte ( from) ) ;
1036+ } else if filters. q . is_some ( ) {
1037+ // Default to 30 days if searching without date range to prevent full table scan
1038+ let thirty_days_ago = Utc :: now ( ) - chrono:: Duration :: days ( 30 ) ;
1039+ condition = condition. add ( CallRecordColumn :: StartedAt . gte ( thirty_days_ago) ) ;
10501040 }
1051- if let Some ( to) = parse_date ( filters. date_to . as_ref ( ) , true ) {
1041+
1042+ if let Some ( to) = date_to {
10521043 condition = condition. add ( CallRecordColumn :: StartedAt . lte ( to) ) ;
10531044 }
10541045
@@ -1469,6 +1460,8 @@ fn build_record_payload(
14691460 let rewrite_destination = json_lookup_nested_str ( & record. metadata , & [ "rewrite" , "destination" ] ) ;
14701461 let billing = build_billing_payload ( record) ;
14711462 let status_code = json_lookup_u16 ( & record. metadata , "status_code" ) ;
1463+ let ring_time = json_lookup_str ( & record. metadata , "ring_time" ) ;
1464+ let answer_time = json_lookup_str ( & record. metadata , "answer_time" ) ;
14721465 let hangup_reason = json_lookup_str ( & record. metadata , "hangup_reason" ) ;
14731466 let hangup_messages = extract_hangup_messages ( & record. metadata ) ;
14741467
@@ -1497,6 +1490,8 @@ fn build_record_payload(
14971490 "recording" : recording,
14981491 "quality" : quality,
14991492 "started_at" : record. started_at. to_rfc3339( ) ,
1493+ "ring_time" : ring_time,
1494+ "answer_time" : answer_time,
15001495 "ended_at" : record. ended_at. map( |dt| dt. to_rfc3339( ) ) ,
15011496 "detail_url" : state. url_for( & format!( "/call-records/{}" , record. id) ) ,
15021497 "billing" : billing,
0 commit comments