Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
[backend] combine async calls and make log a debug
Browse files Browse the repository at this point in the history
  • Loading branch information
YBadiss committed Apr 5, 2024
1 parent e3058eb commit 1cd4ec9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ export class NoteService {
): Promise<Note[]> => {
const lookBackDays =
paramLookBackDays || parseInt(this.config.LOOKBACK_DAYS);
console.log(`Getting notes awaiting rating by ${byAddress} over the last ${lookBackDays} days`);
const notes = await this.reader.getNotes(predicate, lookBackDays);
console.log(`Getting ratings over the last ${lookBackDays} days`);
const ratings = await this.reader.getRatings(lookBackDays);
console.log(`Getting notes and ratings over the last ${lookBackDays} days`);
const [notes, ratings] = await Promise.all([this.reader.getNotes(predicate, lookBackDays), this.reader.getRatings(lookBackDays)])
const ratingsBy = ratings.filter(
(rating) => rating.raterAddress.toLowerCase() === byAddress.toLowerCase(),
);
Expand Down
4 changes: 2 additions & 2 deletions fc-community-backend/apps/api/src/factchain-core/web2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ export class DBConnector implements NoteReader {
timestamp?: number,
): Promise<Note> => {
// TODO: timestamp shouldn't be optional
console.log(`Getting note for postUrl=${postUrl} and creator=${creator} for network ${this._network.NETWORK_NAME}`);
console.debug(`Getting note for postUrl=${postUrl} and creator=${creator} for network ${this._network.NETWORK_NAME}`);
const result = await this._fcCommunity.communityNotes(postUrl, creator);
const note: Note = {
postUrl: result[0],
content: result[1],
creatorAddress: result[2],
finalRating: parseInt(result[3]),
};
console.log(`Successfully retrieved note for postUrl=${postUrl} and creator=${creator} for network ${this._network.NETWORK_NAME}`);
console.debug(`Successfully retrieved note for postUrl=${postUrl} and creator=${creator} for network ${this._network.NETWORK_NAME}`);
if (timestamp !== undefined) {
note.createdAt = timestamp;
}
Expand Down
6 changes: 2 additions & 4 deletions fc-community-backend/apps/shared/src/noteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ export class NoteService {
): Promise<Note[]> => {
const lookBackDays =
paramLookBackDays || parseInt(this.config.LOOKBACK_DAYS);
console.log(`Getting notes awaiting rating by ${byAddress} over the last ${lookBackDays} days`);
const notes = await this.reader.getNotes(predicate, lookBackDays);
console.log(`Getting ratings over the last ${lookBackDays} days`);
const ratings = await this.reader.getRatings(lookBackDays);
console.log(`Getting notes and ratings over the last ${lookBackDays} days`);
const [notes, ratings] = await Promise.all([this.reader.getNotes(predicate, lookBackDays), this.reader.getRatings(lookBackDays)])
const ratingsBy = ratings.filter(
(rating) => rating.raterAddress.toLowerCase() === byAddress.toLowerCase(),
);
Expand Down
4 changes: 2 additions & 2 deletions fc-community-backend/apps/shared/src/web2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ export class DBConnector implements NoteReader {
timestamp?: number,
): Promise<Note> => {
// TODO: timestamp shouldn't be optional
console.log(`Getting note for postUrl=${postUrl} and creator=${creator} for network ${this._network.NETWORK_NAME}`);
console.debug(`Getting note for postUrl=${postUrl} and creator=${creator} for network ${this._network.NETWORK_NAME}`);
const result = await this._fcCommunity.communityNotes(postUrl, creator);
const note: Note = {
postUrl: result[0],
content: result[1],
creatorAddress: result[2],
finalRating: parseInt(result[3]),
};
console.log(`Successfully retrieved note for postUrl=${postUrl} and creator=${creator} for network ${this._network.NETWORK_NAME}`);
console.debug(`Successfully retrieved note for postUrl=${postUrl} and creator=${creator} for network ${this._network.NETWORK_NAME}`);
if (timestamp !== undefined) {
note.createdAt = timestamp;
}
Expand Down

0 comments on commit 1cd4ec9

Please sign in to comment.