Skip to content

Commit

Permalink
Added more logs for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
icemedia001 committed Jan 21, 2025
1 parent 9d932d3 commit 4e4fd06
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/App/Blog/blog.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class BlogService {
.getRepository(HiddenBlog)
.find({ select: ['digest'] })

hiddenDigests = hiddenBlogs.map((blog) => blog.digest)
hiddenDigests = hiddenBlogs.map(blog => blog.digest)
await this.cacheManager.set(this.HIDDEN_BLOGS_CACHE_KEY, hiddenDigests, {
ttl: 7200,
})
Expand All @@ -124,7 +124,7 @@ class BlogService {

private async filterHiddenBlogs(blogs: Blog[]): Promise<Blog[]> {
const hiddenDigests = await this.getHiddenBlogDigests()
return blogs.filter((blog) => !hiddenDigests.includes(blog.digest))
return blogs.filter(blog => !hiddenDigests.includes(blog.digest))
}

async getBlogsFromAccounts(): Promise<Blog[]> {
Expand All @@ -136,21 +136,21 @@ class BlogService {
let blogs = await this.cacheManager.get<Blog[]>(this.BLOG_CACHE_KEY)
if (!blogs) {
blogs = await Promise.all(
accounts.map(async (account) => {
accounts.map(async account => {
try {
if (!account) return []
const entries = await this.mirrorApiService.getBlogs(account)
return (
entries
?.filter((entry) => entry.publishedAtTimestamp)
?.filter(entry => entry.publishedAtTimestamp)
.map((b: Blog) => this.formatBlog(b, true)) || []
)
} catch (error) {
console.log(`Error fetching blogs for account ${account}:`, error)
return []
}
}),
).then((blogArrays) => blogArrays.flat())
).then(blogArrays => blogArrays.flat())
await this.cacheManager.set(this.BLOG_CACHE_KEY, blogs, { ttl: 7200 })
}
return this.filterHiddenBlogs(blogs || [])
Expand Down Expand Up @@ -186,7 +186,7 @@ class BlogService {
timestamp: node.block.timestamp,
}
})
.filter((entry) => entry.slug && entry.slug !== '')
.filter(entry => entry.slug && entry.slug !== '')
.reduce((acc: EntryPath[], current) => {
const x = acc.findIndex(
(entry: EntryPath) => entry.slug === current.slug,
Expand Down Expand Up @@ -319,6 +319,7 @@ class BlogService {
async getHiddenBlogs(): Promise<Blog[]> {
const hiddenBlogsRepo = this.dataSource.getRepository(HiddenBlog)
const hiddenBlogs = await hiddenBlogsRepo.find()
console.log('Hidden blogs fetched from repository:', hiddenBlogs)

let allBlogs = await this.cacheManager.get<Blog[]>(this.BLOG_CACHE_KEY)
if (!allBlogs) {
Expand All @@ -328,32 +329,32 @@ class BlogService {
]

allBlogs = await Promise.all(
accounts.map(async (account) => {
accounts.map(async account => {
try {
if (!account) return []
const entries = await this.mirrorApiService.getBlogs(account)
return (
entries
?.filter((entry) => entry.publishedAtTimestamp)
?.filter(entry => entry.publishedAtTimestamp)
.map((b: Blog) => this.formatBlog(b, true)) || []
)
} catch (error) {
console.error(`Error fetching blogs for account ${account}:`, error)
return []
}
}),
).then((blogArrays) => blogArrays.flat())
).then(blogArrays => blogArrays.flat())

await this.cacheManager.set(this.BLOG_CACHE_KEY, allBlogs, { ttl: 7200 })
}

const hiddenBlogsWithInfo =
allBlogs?.filter((blog) =>
hiddenBlogs.some((hiddenBlog) => hiddenBlog.digest === blog.digest),
allBlogs?.filter(blog =>
hiddenBlogs.some(hiddenBlog => hiddenBlog.digest === blog.digest),
) || []

return hiddenBlogsWithInfo.map((blog) => {
const hiddenBlog = hiddenBlogs.find((hb) => hb.digest === blog.digest)
return hiddenBlogsWithInfo.map(blog => {
const hiddenBlog = hiddenBlogs.find(hb => hb.digest === blog.digest)
return {
...blog,
hiddenAt: hiddenBlog?.hiddenAt,
Expand Down

0 comments on commit 4e4fd06

Please sign in to comment.