Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6172015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:19:14+00:00 2026-05-23T23:19:14+00:00

On my CakePHP 1.3 application there is a product page. On this page it

  • 0

On my CakePHP 1.3 application there is a product page. On this page it shows the current product plus 2 related products.

The related products are found based on this function on the Product Model:

public function related($id, $limit = 2)
{
    $item = $this->find('first',array(
        'fields'=>array('Product.style_number','Product.brand'),
        'conditions'=>array('Product.id'=>$id),
        'recursive'=>0,
    ));

    $data = $this->find('all',array(
        'fields'=>array('Product.id','Product.name','Product.image','Product.url','levenshtein(Product.style_number,"'.$item['Product']['style_number'].'") as dist'),
        'limit'=>$limit,
        'conditions'=>array('NOT'=>array('Product.id'=>$id),'Product.brand'=>$item['Product']['brand']),
        'order'=>'dist',
    ));

    return $data;
}

This function finds the products with the closest style number based on the levenshtein distance. In the query, levenshtein() is a user defined MySQL function you can view source here

When I test this on a table with about 100 rows its fairly fast. However my Product table currently has 10K rows and growing.

I tried adding 'Product.brand'=>$item['Product']['brand'] to limit how many rows it operates on and I also made Product.style_number an index in hopes to speed it up.

Its still pretty slow, it causes about a 2-3 seconds delay when loading the page.

What can I do to make this fast? Is there a way I can cache it..if so how?

Is there a different way I can get the same data faster?

What are my options?

The results I am getting are pretty accurate though, its finding the closest related products.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:19:15+00:00Added an answer on May 23, 2026 at 11:19 pm

    It sounds like this would be a good application for an AJAX workflow. If the distance calculation is taking most of the time (and especially if it’s not a primary part of the page) then you should be able to realize substantial speed-up by running that query separately.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this one CakePHP web application that I'm trying to refactor. There
I have a cakePhp application built, and now I'm creating a simple blog based
I'm trying to get a CakePHP application to work. For this, I've set up
After I uploaded my application created using cakephp, I found out that I had
I have built an application in CakePHP that lists businesses. There are about 2000
let's say i have: http://some-domain/application/controller/action/parameter This is somehow working in cakePHP. Now I want
I'm creating a web application using cakephp 1.2.6. There is a functionality that I
I'm currently working on building an application in CakePHP. There's a quite extensive existing
I have a CakePHP 1.3 application connecting to Solr 3.3 search. There are two
We having been using multiple webservers for our cakephp application, problem is there are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.