Skip to content

Commit 4374e60

Browse files
committed
- Remove deprecated SQL_CALC_FOUND_ROWS from search. And remove the "total" from the results, it wasn't used anyways.
- Add some null coalescing to some idx calls.
1 parent 1615776 commit 4374e60

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

server/actions/patterns/search.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function searchCommunity($query, $startIndex, $limit, $type) {
6969
}
7070

7171
// Do the actual search.
72-
$q = "SELECT SQL_CALC_FOUND_ROWS p.*, urJoin.rating AS userRating, fJoin.patternId as favorite
72+
$q = "SELECT p.*, urJoin.rating AS userRating, fJoin.patternId as favorite
7373
FROM patterns p
7474
LEFT JOIN userRatings urJoin ON urJoin.patternId = p.id AND urJoin.userId = ?
7575
LEFT JOIN favorites as fJoin ON fJoin.userId = ? AND fJoin.patternId=p.id
@@ -94,11 +94,7 @@ public function searchCommunity($query, $startIndex, $limit, $type) {
9494

9595
$result = $this->db->execute($q, $searchSqlParams);
9696

97-
// Returns the total results.
98-
$countQuery = (object)$this->db->execute("SELECT FOUND_ROWS() as count", null, true);
99-
$total = $countQuery->count;
100-
101-
$json = createPatternSet($result, $total, $startIndex, $limit);
97+
$json = createPatternSet($result);
10298

10399
return $json;
104100
}

server/utils.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function convertFromURL($id) {
109109
}
110110

111111
function createPatternNode($row) {
112-
$tool = idx($row, 'state');
112+
$tool = idx($row, 'state') ?? '';
113113

114114
// Replace a few hidden characters with there string counterparts. Otherwise JSON parsing will break.
115115
$tool = preg_replace(["/\n/", "/\r/", "/\t/"], ["\\\\\\n", "\\\\\\r", "\\\\\\t"], $tool);
@@ -138,36 +138,34 @@ function createPatternNode($row) {
138138
$result = array(
139139
'id' => convertToURL(idx($row, 'id')),
140140
'keywords' => idx($row, 'keywords'),
141-
'name' => stripslashes(idx($row, 'name')),
142-
'description' => stripslashes(idx($row, 'description')),
143-
'dateAdded' => strtotime(stripslashes(idx($row, 'dateAdded')))*1000,
141+
'name' => stripslashes(idx($row, 'name') ?? ''),
142+
'description' => stripslashes(idx($row, 'description') ?? ''),
143+
'dateAdded' => strtotime(stripslashes(idx($row, 'dateAdded') ?? ''))*1000,
144144
'flavor' => idx($row, 'flavor'),
145-
'expression' => stripslashes(idx($row, 'pattern')),
145+
'expression' => stripslashes(idx($row, 'pattern') ?? ''),
146146
'text' => idx($row, 'content'),
147147
'tool' => $tool,
148148
'rating' => idx($row, 'rating'),
149149
'userId' => intval(idx($row, 'owner')),
150-
'author' => stripslashes(idx($row, 'author')),
150+
'author' => stripslashes(idx($row, 'author') ?? ''),
151151
'userRating' => idx($row, 'userRating') ?? '0',
152152
'favorite' => !is_null(idx($row, 'favorite')),
153153
'access' => idx($row, 'visibility'),
154154
'mode' => idx($row, 'mode'),
155-
'tests' => json_decode(idx($row, 'tests'))
155+
'tests' => json_decode(idx($row, 'tests') ?? '')
156156
);
157157

158158
return $result;
159159
}
160160

161-
function createPatternSet($result, $total = -1, $startIndex = 0, $limit = 100) {
161+
function createPatternSet($result, $limit = 100) {
162162
$results = array();
163163
for ($i=0;$i<count($result);$i++) {
164164
$results[] = createPatternNode($result[$i]);
165165
}
166166

167167
return array(
168-
'startIndex' => $startIndex,
169168
'limit' => $limit,
170-
'total' => $total,
171169
'results' => $results
172170
);
173171
}

0 commit comments

Comments
 (0)