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

Commit

Permalink
[backend] use rating events to filter out notes
Browse files Browse the repository at this point in the history
  • Loading branch information
YBadiss committed Apr 5, 2024
1 parent 9e329bb commit e3058eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
31 changes: 13 additions & 18 deletions fc-community-backend/apps/api/src/factchain-core/noteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,22 @@ export class NoteService {
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);
// factchainer can't rate their own note
const othersNotes = notes.filter(
(note) => note.creatorAddress.toLowerCase() != byAddress.toLowerCase(),
console.log(`Getting ratings over the last ${lookBackDays} days`);
const ratings = await this.reader.getRatings(lookBackDays);
const ratingsBy = ratings.filter(
(rating) => rating.raterAddress.toLowerCase() === byAddress.toLowerCase(),
);
console.log(`Getting ratings for ${othersNotes.length} notes`);
// factchainer can rate the same note only once
// and can't rate finalised notes
const awaitingRatingBy = await Promise.all(
othersNotes.map(async (note) => {
const rating = await this.reader.getRating(
note.postUrl,
note.creatorAddress,
byAddress,
// factchainer can't rate their own note
const awaitingRatingBy = notes.filter(
(note) => {
return (
!note.finalRating
&& (note.creatorAddress.toLowerCase() != byAddress.toLowerCase())
&& (!ratingsBy.find((rating) => (rating.postUrl === note.postUrl) && (rating.noteCreatorAddress === note.creatorAddress)))
);
if (!rating.value && !note.finalRating) {
return note;
}
return null;
}),
}
);
return awaitingRatingBy.filter((note) => note !== null) as Note[];
return awaitingRatingBy;
};

getNote = async (noteUrl: string, creator: string) => {
Expand Down
31 changes: 13 additions & 18 deletions fc-community-backend/apps/shared/src/noteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,22 @@ export class NoteService {
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);
// factchainer can't rate their own note
const othersNotes = notes.filter(
(note) => note.creatorAddress.toLowerCase() != byAddress.toLowerCase(),
console.log(`Getting ratings over the last ${lookBackDays} days`);
const ratings = await this.reader.getRatings(lookBackDays);
const ratingsBy = ratings.filter(
(rating) => rating.raterAddress.toLowerCase() === byAddress.toLowerCase(),
);
console.log(`Getting ratings for ${othersNotes.length} notes`);
// factchainer can rate the same note only once
// and can't rate finalised notes
const awaitingRatingBy = await Promise.all(
othersNotes.map(async (note) => {
const rating = await this.reader.getRating(
note.postUrl,
note.creatorAddress,
byAddress,
// factchainer can't rate their own note
const awaitingRatingBy = notes.filter(
(note) => {
return (
!note.finalRating
&& (note.creatorAddress.toLowerCase() != byAddress.toLowerCase())
&& (!ratingsBy.find((rating) => (rating.postUrl === note.postUrl) && (rating.noteCreatorAddress === note.creatorAddress)))
);
if (!rating.value && !note.finalRating) {
return note;
}
return null;
}),
}
);
return awaitingRatingBy.filter((note) => note !== null) as Note[];
return awaitingRatingBy;
};

getNote = async (noteUrl: string, creator: string) => {
Expand Down

0 comments on commit e3058eb

Please sign in to comment.