Set limit in random track query itself instead of in connection to optimize query plan

This is a direct backport of
f84644ae3d
master
Randomnicode 5 years ago committed by jvoisin
parent 64fad6a4c5
commit a6a0327b97
  1. 10
      airsonic-main/src/main/java/org/airsonic/player/dao/AbstractDao.java
  2. 4
      airsonic-main/src/main/java/org/airsonic/player/dao/MediaFileDao.java

@ -102,16 +102,6 @@ public class AbstractDao {
return result; return result;
} }
protected <T> List<T> namedQueryWithLimit(String sql, RowMapper<T> rowMapper, Map<String, Object> args, int limit) {
long t = System.nanoTime();
JdbcTemplate jdbcTemplate = new JdbcTemplate(daoHelper.getDataSource());
jdbcTemplate.setMaxRows(limit);
NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(jdbcTemplate);
List<T> result = namedTemplate.query(sql, args, rowMapper);
log(sql, t);
return result;
}
protected List<String> queryForStrings(String sql, Object... args) { protected List<String> queryForStrings(String sql, Object... args) {
long t = System.nanoTime(); long t = System.nanoTime();
List<String> result = getJdbcTemplate().queryForList(sql, args, String.class); List<String> result = getJdbcTemplate().queryForList(sql, args, String.class);

@ -592,7 +592,9 @@ public class MediaFileDao extends AbstractDao {
query += " order by rand()"; query += " order by rand()";
return namedQueryWithLimit(query, rowMapper, args, criteria.getCount()); query += " limit " + criteria.getCount();
return namedQuery(query, rowMapper, args);
} }
public int getAlbumCount(final List<MusicFolder> musicFolders) { public int getAlbumCount(final List<MusicFolder> musicFolders) {

Loading…
Cancel
Save