angularjs + php + mysql(实时搜索)工作缓慢

时间:2015-03-04 15:59:28

标签: php mysql angularjs

我对这堆技术有一个巨大的问题。它适用于我,但在我的数据库中,我有超过50K的记录,它的工作速度没有我想象的那么快。当我试图在我的输入中插入一些字母时,看起来我的电脑没有足够的内存)))

我认为问题可能出在我的PHP代码中。可能是我应该对我的代码做一些优化???

PHP代码

$connect = mysqli_connect("XXXX", "XXX", "XX", "XXX");

$connect->set_charset("utf8");

$result = mysqli_query($connect, 
    "SELECT addresses.fullname AS addressname, addresses.latitude, addresses.longitude, areas.fullname AS areaname, 
    areas.image_url AS areaimage, areas.site, gek.name AS gekName, gek.phone AS gekPhone, gek.email AS gekEmail, 
    gek.description AS gekDescription, gek.addressInformation AS gekAddressInformation
        FROM addresses
        LEFT JOIN areas ON addresses.areaId = areas.id
        left JOIN gek ON addresses.gekId = gek.id");

$data = array();

while ($row = mysqli_fetch_array($result)) {
  $data[] = $row;
}

    echo json_encode($data);

    mysql_close($connect);

我的JS CODE

app.controller('InfoCtrl', ['$scope', '$http', function ($scope, $http) {

        $scope.searchFilter = '';
        $scope.search = function() {};
            $http.get('data/addresses.php')
                .success(function(data) {
                    $scope.addresses = data;
                })
                .error(function() {
                    $scope.data = "Error";
                });
        }
    ]);

HTML CODE

<input type="text" ng-model="searchFilter" placeholder="введите свой адрес"
                    typeahead="address as address.addressname for address in addresses | filter:$viewValue | limitTo:8"
                    ng-focus="showMarker(searchFilter)"
                    typeahead-min-length='1'
                    typeahead-on-select='onSelectPart($item, $model, $label)'
                    class="form-control" />

0 个答案:

没有答案