mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
Merge branch 'dcelasun-configurable-batch-size'
This commit is contained in:
@@ -3,38 +3,6 @@ export interface AddCategoryRequest {
|
|||||||
parentId?: string
|
parentId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApplicationSettings {
|
|
||||||
publicUrl: string
|
|
||||||
allowRegistrations: boolean
|
|
||||||
createDemoAccount: boolean
|
|
||||||
googleAnalyticsTrackingCode?: string
|
|
||||||
googleAuthKey?: string
|
|
||||||
backgroundThreads: number
|
|
||||||
databaseUpdateThreads: number
|
|
||||||
smtpHost?: string
|
|
||||||
smtpPort?: number
|
|
||||||
smtpTls?: boolean
|
|
||||||
smtpUserName?: string
|
|
||||||
smtpPassword?: string
|
|
||||||
smtpFromAddress?: string
|
|
||||||
graphiteEnabled?: boolean
|
|
||||||
graphitePrefix?: string
|
|
||||||
graphiteHost?: string
|
|
||||||
graphitePort?: number
|
|
||||||
graphiteInterval?: number
|
|
||||||
heavyLoad: boolean
|
|
||||||
pubsubhubbub: boolean
|
|
||||||
imageProxyEnabled: boolean
|
|
||||||
queryTimeout: number
|
|
||||||
keepStatusDays: number
|
|
||||||
maxFeedCapacity: number
|
|
||||||
refreshIntervalMinutes: number
|
|
||||||
cache: ApplicationSettingsCache
|
|
||||||
announcement?: string
|
|
||||||
userAgent?: string
|
|
||||||
unreadThreshold?: Date
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Category {
|
export interface Category {
|
||||||
id: string
|
id: string
|
||||||
parentId?: string
|
parentId?: string
|
||||||
@@ -300,8 +268,6 @@ export interface UserModel {
|
|||||||
admin: boolean
|
admin: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ApplicationSettingsCache = "NOOP" | "REDIS"
|
|
||||||
|
|
||||||
export type ReadingMode = "all" | "unread"
|
export type ReadingMode = "all" | "unread"
|
||||||
|
|
||||||
export type ReadingOrder = "asc" | "desc"
|
export type ReadingOrder = "asc" | "desc"
|
||||||
|
|||||||
@@ -27,7 +27,10 @@ app:
|
|||||||
|
|
||||||
# number of database updating threads
|
# number of database updating threads
|
||||||
databaseUpdateThreads: 1
|
databaseUpdateThreads: 1
|
||||||
|
|
||||||
|
# rows to delete per query while cleaning up old entries
|
||||||
|
databaseCleanupBatchSize: 100
|
||||||
|
|
||||||
# settings for sending emails (password recovery)
|
# settings for sending emails (password recovery)
|
||||||
smtpHost: localhost
|
smtpHost: localhost
|
||||||
smtpPort: 25
|
smtpPort: 25
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ app:
|
|||||||
# number of database updating threads
|
# number of database updating threads
|
||||||
databaseUpdateThreads: 1
|
databaseUpdateThreads: 1
|
||||||
|
|
||||||
|
# rows to delete per query while cleaning up old entries
|
||||||
|
databaseCleanupBatchSize: 100
|
||||||
|
|
||||||
# settings for sending emails (password recovery)
|
# settings for sending emails (password recovery)
|
||||||
smtpHost:
|
smtpHost:
|
||||||
smtpPort:
|
smtpPort:
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import javax.validation.Valid;
|
|||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import javax.validation.constraints.Positive;
|
||||||
|
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
|
|
||||||
@@ -95,6 +96,11 @@ public class CommaFeedConfiguration extends Configuration {
|
|||||||
@Valid
|
@Valid
|
||||||
private Integer databaseUpdateThreads;
|
private Integer databaseUpdateThreads;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Positive
|
||||||
|
@Valid
|
||||||
|
private Integer databaseCleanupBatchSize = 100;
|
||||||
|
|
||||||
private String smtpHost;
|
private String smtpHost;
|
||||||
private int smtpPort;
|
private int smtpPort;
|
||||||
private boolean smtpTls;
|
private boolean smtpTls;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.util.List;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import com.commafeed.CommaFeedConfiguration;
|
||||||
import com.commafeed.backend.dao.FeedDAO;
|
import com.commafeed.backend.dao.FeedDAO;
|
||||||
import com.commafeed.backend.dao.FeedEntryContentDAO;
|
import com.commafeed.backend.dao.FeedEntryContentDAO;
|
||||||
import com.commafeed.backend.dao.FeedEntryDAO;
|
import com.commafeed.backend.dao.FeedEntryDAO;
|
||||||
@@ -14,7 +15,6 @@ import com.commafeed.backend.dao.FeedEntryStatusDAO;
|
|||||||
import com.commafeed.backend.dao.UnitOfWork;
|
import com.commafeed.backend.dao.UnitOfWork;
|
||||||
import com.commafeed.backend.model.Feed;
|
import com.commafeed.backend.model.Feed;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,11 +22,10 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor(onConstructor = @__({ @Inject }))
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class DatabaseCleaningService {
|
public class DatabaseCleaningService {
|
||||||
|
|
||||||
private static final int BATCH_SIZE = 100;
|
private final int batchSize;
|
||||||
|
|
||||||
private final UnitOfWork unitOfWork;
|
private final UnitOfWork unitOfWork;
|
||||||
private final FeedDAO feedDAO;
|
private final FeedDAO feedDAO;
|
||||||
@@ -34,6 +33,17 @@ public class DatabaseCleaningService {
|
|||||||
private final FeedEntryContentDAO feedEntryContentDAO;
|
private final FeedEntryContentDAO feedEntryContentDAO;
|
||||||
private final FeedEntryStatusDAO feedEntryStatusDAO;
|
private final FeedEntryStatusDAO feedEntryStatusDAO;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public DatabaseCleaningService(CommaFeedConfiguration config, UnitOfWork unitOfWork, FeedDAO feedDAO, FeedEntryDAO feedEntryDAO,
|
||||||
|
FeedEntryContentDAO feedEntryContentDAO, FeedEntryStatusDAO feedEntryStatusDAO) {
|
||||||
|
this.unitOfWork = unitOfWork;
|
||||||
|
this.feedDAO = feedDAO;
|
||||||
|
this.feedEntryDAO = feedEntryDAO;
|
||||||
|
this.feedEntryContentDAO = feedEntryContentDAO;
|
||||||
|
this.feedEntryStatusDAO = feedEntryStatusDAO;
|
||||||
|
this.batchSize = config.getApplicationSettings().getDatabaseCleanupBatchSize();
|
||||||
|
}
|
||||||
|
|
||||||
public void cleanFeedsWithoutSubscriptions() {
|
public void cleanFeedsWithoutSubscriptions() {
|
||||||
log.info("cleaning feeds without subscriptions");
|
log.info("cleaning feeds without subscriptions");
|
||||||
long total = 0;
|
long total = 0;
|
||||||
@@ -44,7 +54,7 @@ public class DatabaseCleaningService {
|
|||||||
for (Feed feed : feeds) {
|
for (Feed feed : feeds) {
|
||||||
long entriesDeleted;
|
long entriesDeleted;
|
||||||
do {
|
do {
|
||||||
entriesDeleted = unitOfWork.call(() -> feedEntryDAO.delete(feed.getId(), BATCH_SIZE));
|
entriesDeleted = unitOfWork.call(() -> feedEntryDAO.delete(feed.getId(), batchSize));
|
||||||
entriesTotal += entriesDeleted;
|
entriesTotal += entriesDeleted;
|
||||||
log.info("removed {} entries for feeds without subscriptions", entriesTotal);
|
log.info("removed {} entries for feeds without subscriptions", entriesTotal);
|
||||||
} while (entriesDeleted > 0);
|
} while (entriesDeleted > 0);
|
||||||
@@ -61,7 +71,7 @@ public class DatabaseCleaningService {
|
|||||||
long total = 0;
|
long total = 0;
|
||||||
long deleted;
|
long deleted;
|
||||||
do {
|
do {
|
||||||
deleted = unitOfWork.call(() -> feedEntryContentDAO.deleteWithoutEntries(BATCH_SIZE));
|
deleted = unitOfWork.call(() -> feedEntryContentDAO.deleteWithoutEntries(batchSize));
|
||||||
total += deleted;
|
total += deleted;
|
||||||
log.info("removed {} contents without entries", total);
|
log.info("removed {} contents without entries", total);
|
||||||
} while (deleted != 0);
|
} while (deleted != 0);
|
||||||
@@ -71,7 +81,7 @@ public class DatabaseCleaningService {
|
|||||||
public void cleanEntriesForFeedsExceedingCapacity(final int maxFeedCapacity) {
|
public void cleanEntriesForFeedsExceedingCapacity(final int maxFeedCapacity) {
|
||||||
long total = 0;
|
long total = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
List<FeedCapacity> feeds = unitOfWork.call(() -> feedEntryDAO.findFeedsExceedingCapacity(maxFeedCapacity, BATCH_SIZE));
|
List<FeedCapacity> feeds = unitOfWork.call(() -> feedEntryDAO.findFeedsExceedingCapacity(maxFeedCapacity, batchSize));
|
||||||
if (feeds.isEmpty()) {
|
if (feeds.isEmpty()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -80,7 +90,7 @@ public class DatabaseCleaningService {
|
|||||||
long remaining = feed.getCapacity() - maxFeedCapacity;
|
long remaining = feed.getCapacity() - maxFeedCapacity;
|
||||||
do {
|
do {
|
||||||
final long rem = remaining;
|
final long rem = remaining;
|
||||||
int deleted = unitOfWork.call(() -> feedEntryDAO.deleteOldEntries(feed.getId(), Math.min(BATCH_SIZE, rem)));
|
int deleted = unitOfWork.call(() -> feedEntryDAO.deleteOldEntries(feed.getId(), Math.min(batchSize, rem)));
|
||||||
total += deleted;
|
total += deleted;
|
||||||
remaining -= deleted;
|
remaining -= deleted;
|
||||||
log.info("removed {} entries for feeds exceeding capacity", total);
|
log.info("removed {} entries for feeds exceeding capacity", total);
|
||||||
@@ -95,7 +105,7 @@ public class DatabaseCleaningService {
|
|||||||
long total = 0;
|
long total = 0;
|
||||||
long deleted;
|
long deleted;
|
||||||
do {
|
do {
|
||||||
deleted = unitOfWork.call(() -> feedEntryStatusDAO.deleteOldStatuses(olderThan, BATCH_SIZE));
|
deleted = unitOfWork.call(() -> feedEntryStatusDAO.deleteOldStatuses(olderThan, batchSize));
|
||||||
total += deleted;
|
total += deleted;
|
||||||
log.info("removed {} old read statuses", total);
|
log.info("removed {} old read statuses", total);
|
||||||
} while (deleted != 0);
|
} while (deleted != 0);
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ app:
|
|||||||
# number of database updating threads
|
# number of database updating threads
|
||||||
databaseUpdateThreads: 1
|
databaseUpdateThreads: 1
|
||||||
|
|
||||||
|
# rows to delete per query while cleaning up old entries
|
||||||
|
databaseCleanupBatchSize: 100
|
||||||
|
|
||||||
# settings for sending emails (password recovery)
|
# settings for sending emails (password recovery)
|
||||||
smtpHost: localhost
|
smtpHost: localhost
|
||||||
smtpPort: 25
|
smtpPort: 25
|
||||||
|
|||||||
Reference in New Issue
Block a user