mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
admin cleanup interface
This commit is contained in:
@@ -10,13 +10,11 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.commafeed.backend.dao.FeedDAO;
|
||||
import com.commafeed.backend.dao.FeedDAO.FeedCount;
|
||||
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionDAO;
|
||||
import com.commafeed.backend.model.Feed;
|
||||
import com.commafeed.backend.model.FeedSubscription;
|
||||
import com.commafeed.backend.services.ApplicationSettingsService;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class DatabaseCleaner {
|
||||
|
||||
@@ -75,44 +73,6 @@ public class DatabaseCleaner {
|
||||
return total;
|
||||
}
|
||||
|
||||
public long cleanDuplicateFeeds() {
|
||||
long total = 0;
|
||||
int deleted = -1;
|
||||
do {
|
||||
List<FeedCount> fcs = feedDAO
|
||||
.findDuplicates(0, applicationSettingsService.get()
|
||||
.getDatabaseUpdateThreads(), 1);
|
||||
deleted = fcs.size();
|
||||
|
||||
List<Thread> threads = Lists.newArrayList();
|
||||
for (final FeedCount fc : fcs) {
|
||||
Thread thread = new Thread() {
|
||||
public void run() {
|
||||
Feed into = feedDAO.findById(fc.feeds.get(0).getId());
|
||||
List<Feed> feeds = Lists.newArrayList();
|
||||
for (Feed feed : fc.feeds) {
|
||||
feeds.add(feedDAO.findById(feed.getId()));
|
||||
}
|
||||
mergeFeeds(into, feeds);
|
||||
};
|
||||
};
|
||||
thread.start();
|
||||
threads.add(thread);
|
||||
}
|
||||
for (Thread thread : threads) {
|
||||
try {
|
||||
thread.join();
|
||||
} catch (InterruptedException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
total += deleted;
|
||||
log.info("merged {} feeds", total);
|
||||
} while (deleted != 0);
|
||||
log.info("cleanup done: {} feeds merged", total);
|
||||
return total;
|
||||
}
|
||||
|
||||
public void mergeFeeds(Feed into, List<Feed> feeds) {
|
||||
for (Feed feed : feeds) {
|
||||
if (into.getId().equals(feed.getId())) {
|
||||
|
||||
Reference in New Issue
Block a user