🐛 fix: Fixed the query problem of stored file list.
This commit is contained in:
parent
27e1d6c46f
commit
15c83639a7
1 changed files with 7 additions and 6 deletions
|
|
@ -106,10 +106,6 @@ public class FileRepositoryImpl implements FileRepository {
|
||||||
whereClause += " AND (file_name LIKE #{search} OR caption LIKE #{search})";
|
whereClause += " AND (file_name LIKE #{search} OR caption LIKE #{search})";
|
||||||
params.put("search", "%%" + search + "%%");
|
params.put("search", "%%" + search + "%%");
|
||||||
}
|
}
|
||||||
if (fromMessageId > 0) {
|
|
||||||
whereClause += " AND message_id > #{fromMessageId}";
|
|
||||||
params.put("fromMessageId", fromMessageId);
|
|
||||||
}
|
|
||||||
if (StrUtil.isNotBlank(type)) {
|
if (StrUtil.isNotBlank(type)) {
|
||||||
if (Objects.equals(type, "media")) {
|
if (Objects.equals(type, "media")) {
|
||||||
whereClause += " AND type IN ('photo', 'video')";
|
whereClause += " AND type IN ('photo', 'video')";
|
||||||
|
|
@ -118,10 +114,15 @@ public class FileRepositoryImpl implements FileRepository {
|
||||||
params.put("type", type);
|
params.put("type", type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String countClause = whereClause;
|
||||||
|
if (fromMessageId > 0) {
|
||||||
|
whereClause += " AND message_id < #{fromMessageId}";
|
||||||
|
params.put("fromMessageId", fromMessageId);
|
||||||
|
}
|
||||||
return Future.all(
|
return Future.all(
|
||||||
SqlTemplate
|
SqlTemplate
|
||||||
.forQuery(pool, """
|
.forQuery(pool, """
|
||||||
SELECT * FROM file_record WHERE %s ORDER BY date DESC LIMIT 20
|
SELECT * FROM file_record WHERE %s ORDER BY message_id desc LIMIT 20
|
||||||
""".formatted(whereClause))
|
""".formatted(whereClause))
|
||||||
.mapTo(FileRecord.ROW_MAPPER)
|
.mapTo(FileRecord.ROW_MAPPER)
|
||||||
.execute(params)
|
.execute(params)
|
||||||
|
|
@ -131,7 +132,7 @@ public class FileRepositoryImpl implements FileRepository {
|
||||||
SqlTemplate
|
SqlTemplate
|
||||||
.forQuery(pool, """
|
.forQuery(pool, """
|
||||||
SELECT COUNT(*) FROM file_record WHERE %s
|
SELECT COUNT(*) FROM file_record WHERE %s
|
||||||
""".formatted(whereClause))
|
""".formatted(countClause))
|
||||||
.mapTo(rs -> rs.getLong(0))
|
.mapTo(rs -> rs.getLong(0))
|
||||||
.execute(params)
|
.execute(params)
|
||||||
.onFailure(err -> log.error("Failed to get file record count: %s".formatted(err.getMessage())))
|
.onFailure(err -> log.error("Failed to get file record count: %s".formatted(err.getMessage())))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue