优化社区搜索历史数据库操作
This commit is contained in:
@ -27,25 +27,30 @@ public class AskSearchHistoryDao {
|
||||
|
||||
public void add(String key, String communityId) {
|
||||
try {
|
||||
List<String> all = getAll(communityId);
|
||||
if (!all.contains(key)) dao.createOrUpdate(new AskSearchHistoryInfo(key, communityId));
|
||||
dao.createOrUpdate(createInfo(key, communityId));
|
||||
} catch (SQLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(String item) {
|
||||
private AskSearchHistoryInfo createInfo(String key, String communityId) {
|
||||
try {
|
||||
dao.deleteById(item);
|
||||
List<AskSearchHistoryInfo> his = dao.queryBuilder().
|
||||
orderBy("time", false).
|
||||
where().eq("communityId", communityId).
|
||||
query();
|
||||
for (AskSearchHistoryInfo next : his) {
|
||||
if (next.getKey().equals(key)) dao.delete(next);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return new AskSearchHistoryInfo(key, communityId);
|
||||
}
|
||||
|
||||
public void deleteAll() {
|
||||
|
||||
CloseableIterator<AskSearchHistoryInfo> iterator = dao.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user