Skip to content

Commit

Permalink
Fix urls calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Feb 7, 2024
1 parent 9232213 commit d0846b1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/feeds/FeedReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ function normalizeUrl(input: string): string {
export class FeedReader {

private connections: FeedConnection[];
// ts should notice that we do in fact initialize it in constructor, but it doesn't (in this version)
private observedFeedUrls: Set<string> = new Set();

private feedQueue = new QueueWithBackoff();

Expand Down Expand Up @@ -113,7 +111,7 @@ export class FeedReader {
this.timeouts.fill(undefined);
Object.seal(this.timeouts);
this.connections = this.connectionManager.getAllConnectionsOfType(FeedConnection);
this.calculateFeedUrls();
const initialFeeds = this.calculateFeedUrls();
connectionManager.on('new-connection', c => {
if (c instanceof FeedConnection) {
log.debug('New connection tracked:', c.connectionId);
Expand All @@ -128,7 +126,7 @@ export class FeedReader {
}
});

log.debug('Loaded feed URLs:', this.observedFeedUrls);
log.debug('Loaded feed URLs:', [...initialFeeds].join(', '));

for (let i = 0; i < config.pollConcurrency; i++) {
void this.pollFeeds(i);
Expand All @@ -140,7 +138,7 @@ export class FeedReader {
this.timeouts.forEach(t => clearTimeout(t));
}

private calculateFeedUrls(): void {
private calculateFeedUrls(): Set<string> {
// just in case we got an invalid URL somehow
const observedFeedUrls = new Set<string>();
for (const conn of this.connections) {
Expand All @@ -150,11 +148,14 @@ export class FeedReader {
log.error(`Invalid feedUrl for connection ${conn.connectionId}: ${conn.feedUrl}. It will not be tracked`);
}
}
observedFeedUrls.add("http://example.com/not-an-rss-feed");
observedFeedUrls.forEach(url => this.feedQueue.push(url));
this.feedQueue.shuffle();

Metrics.feedsCount.set(this.observedFeedUrls.size);
Metrics.feedsCountDeprecated.set(this.observedFeedUrls.size);

Metrics.feedsCount.set(observedFeedUrls.size);
Metrics.feedsCountDeprecated.set(observedFeedUrls.size);
return observedFeedUrls;
}

/**
Expand Down

0 comments on commit d0846b1

Please sign in to comment.