Skip to content

[improvement]: Increase Speed of Superfecta Contact Manager Lookup #1058

Description

@rwall88-rgb

FreePBX Version

FreePBX 17

Improvement Description

Performance Improvement Suggestion: Superfecta Contact Manager Lookup

While troubleshooting slow Caller ID lookups on a FreePBX 17 system, I noticed what appears to be a significant performance optimization opportunity in the Superfecta Contact Manager source. I changed 1 line of code to make the superfecta contact manager lookup 67x faster... shaving off nearly 3.5 seconds per search.

Environment

  • FreePBX Framework: 17.0.28
  • Contact Manager: 17.0.6.2
  • Superfecta: 17.0.7

Contact Database Size

  • Contacts: 7,667
  • Phone number entries: 8,622

Current Implementation

The Superfecta Contact Manager source currently calls:

$data = FreePBX::Contactmanager()->lookupByUserID(-1, $thenumber, "/[^\+\d]/");

While investigating the performance, I found that lookupByUserID() ultimately loads the complete contact list into PHP and performs a recursive search through every field of every contact.

Existing Contact Manager Function

The Contact Manager module already contains a function specifically designed for telephone number lookups:

lookupNumberByUserID($id, $number, $search_groups = null)

This function first performs a SQL lookup against the Contact Manager phone number tables and only falls back to a broader search if necessary.

Test

I modified only one line in the Superfecta Contact Manager source:

From:

lookupByUserID(-1, $thenumber, "/[^\+\d]/");

To:

lookupNumberByUserID(-1, $thenumber);

No other code was changed.

Results

Before:

Executing FreePBX Contactmanager
result took 3.5749 seconds

After:

Executing FreePBX Contactmanager
result took 0.0534 seconds

This was approximately a 67× improvement.

Functional Testing

The returned Caller ID remained identical.

The optimized lookup correctly matched all of the following formats:

4044041100
14044041100
+14044041100
+1(404)404-1100

Live inbound calls also displayed the correct Caller ID.

Question

Is there a compatibility or historical reason that Superfecta currently uses lookupByUserID() instead of lookupNumberByUserID()?

If not, it seems this could significantly improve Contact Manager lookup performance, particularly on systems with several thousand contacts, while preserving the existing behavior.

If there is an edge case that lookupByUserID() handles differently, I'd be interested in understanding it before relying on this optimization long-term.

Thanks for taking a look, and thanks for all the work that goes into FreePBX.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions