Move PHP filtering calls to the SQL layer#4580
Open
priestjim wants to merge 1 commit into
Open
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR's intention is to improve the performance of
phpipamby moving PHP filtering to SQL filtering wherever possible. Here are the changes made, broken down by file and changeset:Common.php$filter_appliedflag to skip redundant PHP filtering when SQL filter was usedpcre_to_mysql_regexp()- converts PCRE patterns to MySQL REGEXP syntaxbuild_sql_filter_condition()- translates APIfilter_by/filter_value/filter_matchparams into SQLWHEREclauses with proper reverse key mapping (deviceId→switch,tag→state,ip→ip_addr)fetch_all_with_filter()- wrapsfetch allqueries with optional SQL-level filtering, falling back to full fetch when no filter is setAddresses.phpGETall - usesfetch_all_with_filter("ipaddresses")instead of fetching everythingGETby IP in subnet - direct SQL query onip_addr+subnetIdinstead of fetching all addresses then PHP-filteringGETtags with subnetId - SQL WHERE onstate+subnetIdinstead of fetching all by state then loopingDELETEby IP+subnet - direct SQL lookup instead of fetching all by IP then loopingSubnets.phpGET /{id}/addresses/{ip}- direct SQL query onsubnetId+ip_addrinstead of fetching all subnet addresses then PHP-filtering by IPGETall subnets - usesfetch_all_with_filter("subnets")for the initial fetch insideread_all_subnets()WHERE subnet = ? AND mask = ?instead of fetching by subnet then PHP-filtering by maskVlans.phpGETall - usesfetch_all_with_filter("vlans", "vlanId")GET/{id}/subnets/{sectionId}- SQLWHERE vlanId = ? AND sectionId = ?instead of fetching all VLAN subnets then PHP-filteringvalidate_vlan_edit- SQLWHERE domainId = ? AND number = ? LIMIT 1instead of fetching all VLANs in domain then loopingDevices.php,Sections.php,Tools.phpfetch_all_with_filter()to push genericfilter_by/filter_value/filter_matchfiltering down to SQL