Skip to content

Move PHP filtering calls to the SQL layer#4580

Open
priestjim wants to merge 1 commit into
phpipam:1.7from
priestjim:1.7
Open

Move PHP filtering calls to the SQL layer#4580
priestjim wants to merge 1 commit into
phpipam:1.7from
priestjim:1.7

Conversation

@priestjim

Copy link
Copy Markdown

Description

This PR's intention is to improve the performance of phpipam by moving PHP filtering to SQL filtering wherever possible. Here are the changes made, broken down by file and changeset:

Common.php

  • Added $filter_applied flag to skip redundant PHP filtering when SQL filter was used
  • Added pcre_to_mysql_regexp() - converts PCRE patterns to MySQL REGEXP syntax
  • Added build_sql_filter_condition() - translates API filter_by/filter_value/filter_match params into SQL WHERE clauses with proper reverse key mapping (deviceIdswitch, tagstate, ipip_addr)
  • Added fetch_all_with_filter() - wraps fetch all queries with optional SQL-level filtering, falling back to full fetch when no filter is set

Addresses.php

  1. GET all - uses fetch_all_with_filter("ipaddresses") instead of fetching everything
  2. GET by IP in subnet - direct SQL query on ip_addr + subnetId instead of fetching all addresses then PHP-filtering
  3. GET tags with subnetId - SQL WHERE on state + subnetId instead of fetching all by state then looping
  4. DELETE by IP+subnet - direct SQL lookup instead of fetching all by IP then looping

Subnets.php

  1. GET /{id}/addresses/{ip} - direct SQL query on subnetId + ip_addr instead of fetching all subnet addresses then PHP-filtering by IP
  2. GET all subnets - uses fetch_all_with_filter("subnets") for the initial fetch inside read_all_subnets()
  3. Search subnet - SQL WHERE subnet = ? AND mask = ? instead of fetching by subnet then PHP-filtering by mask

Vlans.php

  1. GET all - uses fetch_all_with_filter("vlans", "vlanId")
  2. GET /{id}/subnets/{sectionId} - SQL WHERE vlanId = ? AND sectionId = ? instead of fetching all VLAN subnets then PHP-filtering
  3. validate_vlan_edit - SQL WHERE domainId = ? AND number = ? LIMIT 1 instead of fetching all VLANs in domain then looping

Devices.php, Sections.php, Tools.php

  • All "fetch all" GET endpoints now use fetch_all_with_filter() to push generic filter_by/filter_value/filter_match filtering down to SQL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant