-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update SugarModules/modules/Asterisk/include/callListener.php
- Loading branch information
Showing
1 changed file
with
3 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6e24e2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to add the joined table conditions to the WHERE clause to make the LEFT JOIN work.
You have just to add the (ac.deleted='0') condition to ON clause.
replace
FROM contacts c left join accounts_contacts ac on (c.id=ac.contact_id) left join accounts a on (ac.account_id=a.id)
by
FROM contacts c
LEFT JOIN accounts_contacts ac
ON (c.id=ac.contact_id) AND ac.deleted='0'
LEFT JOIN accounts a
ON (ac.account_id=a.id) AND a.deleted='0'
and replace
$wherePortion = " WHERE c.id='{$row['contact_id']}' and c.deleted='0' and (ac.deleted='0' or ac.deleted is null) and (a.deleted='0' or a.deleted is null)";
by
$wherePortion = " WHERE c.id='{$row['contact_id']}' and c.deleted='0'";
6e24e2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Guard1an Thanks so much!!!
That makes total sense that you could do that but I'm not very experienced with SQL so I didn't know! I'm traveling for the next 2 weeks so I will incorporate your fix then.
Since you seem to be great with databases... any chance you could take a look at optimizing a query for me? I explain the issue in detail here:
https://github.com/blak3r/yaai/wiki/Project-TODO-List#wiki-Issue_1_Optimize_callListenerphp
The answer is probably as simple as index such and such column. I just haven't gotten around to learning about the MYSQL EXPLAIN command.
Thanks again for your contribution.
6e24e2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right,
Adding indexes for the fields being searched should increase the performance.
I would rather recoment to optimize the table structure: use ENUM instead of VARCHAR for *state fields and add appropriate constants in Php.
You can check the result of SELECT * FROM asterisk_log PROCEDURE ANALYSE(); for further details.
Regarding the callListener.php performance in general, I would recoment to implement SQL query result caching in PHP.
We can remove the 'channel' condition from the query or replace it by LIKE 'SIP/%' to fetch the result for all extensions, cache the serialized array in PHP where keys equal to extension.
6e24e2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this would be fairly difficult. I think the state names vary slightly between versions.
I like your query cache idea. Any chance you could implement it and provide a pull request?