mirror of
https://github.com/zoriya/flood.git
synced 2026-06-06 03:56:42 +00:00
server: replace explicit binds with arrow functions
This commit is contained in:
@@ -37,7 +37,7 @@ class DiskUsage extends (EventEmitter as new () => TypedEmitter<DiskUsageEvents>
|
||||
// start polling disk usage when the first listener is added
|
||||
this.on('newListener', (event) => {
|
||||
if (this.listenerCount('DISK_USAGE_CHANGE') === 0 && event === 'DISK_USAGE_CHANGE') {
|
||||
this.updateInterval = setInterval(this.updateDisks.bind(this), INTERVAL_UPDATE);
|
||||
this.updateInterval = setInterval(this.updateDisks, INTERVAL_UPDATE);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -53,7 +53,7 @@ class DiskUsage extends (EventEmitter as new () => TypedEmitter<DiskUsageEvents>
|
||||
});
|
||||
}
|
||||
|
||||
updateDisks() {
|
||||
updateDisks = () => {
|
||||
if (!isPlatformSupported()) {
|
||||
return Promise.reject();
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class DiskUsage extends (EventEmitter as new () => TypedEmitter<DiskUsageEvents>
|
||||
this.emit('DISK_USAGE_CHANGE', this.getDiskUsage());
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
getDiskUsage(): DiskUsageSummary {
|
||||
return {
|
||||
|
||||
@@ -35,7 +35,7 @@ class FeedReader {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
handleFeedItems(items: Array<FeedItem>) {
|
||||
handleFeedItems = (items: Array<FeedItem>) => {
|
||||
const nextLength = this.items.length + items.length;
|
||||
if (nextLength >= this.options.maxHistory) {
|
||||
const diff = nextLength - this.options.maxHistory;
|
||||
@@ -45,7 +45,7 @@ class FeedReader {
|
||||
this.items = this.items.concat(items);
|
||||
|
||||
this.options.onNewItems(this.options, items);
|
||||
}
|
||||
};
|
||||
|
||||
initReader() {
|
||||
this.reader = new FeedSub(this.options.url, {
|
||||
@@ -56,7 +56,7 @@ class FeedReader {
|
||||
forceInterval: true,
|
||||
});
|
||||
|
||||
this.reader.on('items', this.handleFeedItems.bind(this));
|
||||
this.reader.on('items', this.handleFeedItems);
|
||||
this.reader.on('error', (error) => {
|
||||
console.log('Feed reader error:', error);
|
||||
});
|
||||
|
||||
@@ -40,7 +40,7 @@ class HistoryEra {
|
||||
cleanupInterval = config.dbCleanInterval;
|
||||
}
|
||||
|
||||
this.startAutoCleanup(cleanupInterval, this.db);
|
||||
this.autoCleanupInterval = setInterval(this.cleanup, cleanupInterval);
|
||||
}
|
||||
|
||||
loadDatabase(userId: UserInDatabase['_id'], dbName: string) {
|
||||
@@ -91,10 +91,10 @@ class HistoryEra {
|
||||
}
|
||||
}
|
||||
|
||||
cleanup(db: this['db']) {
|
||||
this.removeOutdatedData(db);
|
||||
db.persistence.compactDatafile();
|
||||
}
|
||||
cleanup = () => {
|
||||
this.removeOutdatedData(this.db);
|
||||
this.db.persistence.compactDatafile();
|
||||
};
|
||||
|
||||
getData(callback: (snapshots: Array<TransferSnapshot> | null, error?: Error) => void) {
|
||||
const minTimestamp = Date.now() - this.opts.maxTime;
|
||||
@@ -147,40 +147,18 @@ class HistoryEra {
|
||||
}
|
||||
|
||||
if (nextEraUpdateInterval) {
|
||||
this.startNextEraUpdate(nextEraUpdateInterval, this.db);
|
||||
this.nextEraUpdateInterval = setInterval(this.updateNextEra, nextEraUpdateInterval);
|
||||
}
|
||||
}
|
||||
|
||||
startAutoCleanup(interval: number, db: this['db']): void {
|
||||
this.autoCleanupInterval = setInterval(this.cleanup.bind(this, db), interval);
|
||||
}
|
||||
|
||||
startNextEraUpdate(interval: number, currentDB: this['db']): void {
|
||||
this.nextEraUpdateInterval = setInterval(this.updateNextEra.bind(this, currentDB), interval);
|
||||
}
|
||||
|
||||
stopAutoCleanup(): void {
|
||||
if (this.autoCleanupInterval != null) {
|
||||
clearInterval(this.autoCleanupInterval);
|
||||
delete this.autoCleanupInterval;
|
||||
}
|
||||
}
|
||||
|
||||
stopNextEraUpdate(): void {
|
||||
if (this.nextEraUpdateInterval != null) {
|
||||
clearInterval(this.nextEraUpdateInterval);
|
||||
delete this.nextEraUpdateInterval;
|
||||
}
|
||||
}
|
||||
|
||||
updateNextEra(currentDB: this['db']): void {
|
||||
updateNextEra = (): void => {
|
||||
if (this.opts.nextEraUpdateInterval == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const minTimestamp = Date.now() - this.opts.nextEraUpdateInterval;
|
||||
|
||||
currentDB.find({timestamp: {$gte: minTimestamp}}, (err: Error, snapshots: Array<TransferSnapshot>) => {
|
||||
this.db.find({timestamp: {$gte: minTimestamp}}, (err: Error, snapshots: Array<TransferSnapshot>) => {
|
||||
if (err || this.opts.nextEra == null) {
|
||||
return;
|
||||
}
|
||||
@@ -198,7 +176,7 @@ class HistoryEra {
|
||||
upload: Number(Number(upTotal / snapshots.length).toFixed(1)),
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default HistoryEra;
|
||||
|
||||
Reference in New Issue
Block a user