Skip to content

Commit de9746f

Browse files
committed
Limited support for fulltext replay search
1 parent 843728f commit de9746f

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/actions.ts

+19
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,13 @@ export const actions: {[k: string]: QueryHandler} = {
893893
throw new ActionError(`Cannot set both "page" and "before", please choose one method of pagination`);
894894
}
895895

896+
if (params.contains) {
897+
if (Object.keys(params).length > 1) {
898+
throw new ActionError(`Contains can't be combined with other things.`);
899+
}
900+
return Replays.fullSearch(params.contains);
901+
}
902+
896903
const search = {
897904
usernames: usernames,
898905
format: toID(params.format),
@@ -923,6 +930,18 @@ export const actions: {[k: string]: QueryHandler} = {
923930
throw new ActionError(`Cannot set both "page" and "before", please choose one method of pagination`);
924931
}
925932

933+
if (params.contains) {
934+
if (Object.keys(params).length > 2) {
935+
throw new ActionError(`Contains can't be combined with other things.`);
936+
}
937+
this.response.setHeader('Content-Type', 'application/json');
938+
try {
939+
return JSON.stringify(await Replays.fullSearch(params.contains));
940+
} catch (e) {
941+
throw new ActionError(`Could not search (timeout?)`);
942+
}
943+
}
944+
926945
const search = {
927946
usernames: usernames,
928947
format: toID(params.format),

src/replays.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ export const Replays = new class {
213213
});
214214
if (patterns.length !== 1 && patterns.length !== 2) return Promise.resolve([]);
215215

216-
const secondPattern = patterns.length >= 2 ? SQL`AND log LIKE ${patterns[1]} ` : undefined;
216+
const secondPattern = patterns.length >= 2 ? SQL`AND log LIKE ${patterns[1]} ` : SQL``;
217217

218-
const DAYS = 24 * 60 * 60;
218+
const HOUR = 60 * 60;
219219
return replays.query()`SELECT
220-
uploadtime, id, format, players, rating FROM ps_replays
221-
WHERE private = 0 AND uploadtime > ${time() - 3 * DAYS} AND log LIKE ${patterns[0]} ${secondPattern}
220+
uploadtime, id, format, players, rating FROM replays
221+
WHERE private = 0 AND uploadtime > ${time() - HOUR} AND log LIKE ${patterns[0]} ${secondPattern}
222222
ORDER BY uploadtime DESC LIMIT 50;`.then(this.toReplays);
223223
}
224224

0 commit comments

Comments
 (0)