From 68dcad8c70e80eab312c9614fee7e6809f41168b Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Wed, 13 Oct 2021 16:21:20 +0200 Subject: [PATCH] TT#139550 improve vmnotify messaging * improve select from voicemail_spool to avoid sequental scan with like '%..' * select now fetches all messages count * add old messages count support * old/new messages are reported as 0 if not returned from voicemail_spool Change-Id: I11ac1a407e8d22fe828a17cda55aa3298c6e6f02 --- lib/NGCP/Panel/Utils/Subscriber.pm | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/NGCP/Panel/Utils/Subscriber.pm b/lib/NGCP/Panel/Utils/Subscriber.pm index c0f0fb8872..0aba99af62 100644 --- a/lib/NGCP/Panel/Utils/Subscriber.pm +++ b/lib/NGCP/Panel/Utils/Subscriber.pm @@ -2270,8 +2270,7 @@ sub update_voicemail_number { sub vmnotify{ my (%params) = @_; - my $c = $params{c}; - my $voicemail = $params{voicemail}; + my ($c, $voicemail) = @params{qw(c voicemail)}; #1.although method is called after delete - DBIC still can access data in deleted row #2.amount of the new messages should be selected after played update or delete, of course @@ -2279,16 +2278,30 @@ sub vmnotify{ $data->{cli} = $voicemail->mailboxuser->provisioning_voip_subscriber->username; $data->{uuid} = $voicemail->mailboxuser->provisioning_voip_subscriber->uuid; $data->{context} = 'default'; + $data->{old_messages} = 0; + $data->{new_messages} = 0; - $data->{messages_amount} = $c->model('DB')->resultset('voicemail_spool')->find({ + my $msg_rs = $c->model('DB')->resultset('voicemail_spool')->search({ 'mailboxuser' => $data->{mailboxuser}, - 'msgnum' => { '>=' => 0 }, - 'dir' => { 'like' => '%/INBOX' }, },{ - 'select' => [{'count' => '*', -as => 'messages_number'}] - })->get_column('messages_number'); + 'select' => [ + 'dir', + { 'count' => 'dir', -as => 'dir_count'}, + + ], + 'group_by' => 'dir', + }); + + foreach my $r ($msg_rs->all) { + my %row = $r->get_inflated_columns; + if ($row{dir} =~ m#/INBOX$#) { + $data->{new_messages} = $row{dir_count} + } elsif ($row{dir} =~ m#/Old$#) { + $data->{old_messages} = $row{dir_count}; + } + } - my @cmd = ('ngcp-vmnotify', @$data{qw/context cli uuid messages_amount/}); + my @cmd = ('ngcp-vmnotify', @$data{qw/context cli uuid new_messages old_messages/}); my $output = capturex([0..3],@cmd); $c->log->debug("cmd=".join(" ", @cmd)."; output=$output;"); return;