refactor: simplify distance time and optimize image fetching

This commit is contained in:
Simon He 2024-10-18 15:16:42 +08:00 committed by GitHub
parent 7847da8432
commit 1d079e1fb3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 8 deletions

View File

@ -25,6 +25,7 @@ export const useFeedStore = createZustandStore<FeedState>("feed")(() => ({
const set = useFeedStore.setState
const get = useFeedStore.getState
const distanceTime = 1000 * 60 * 60 * 9
class FeedActions {
clear() {
set({ feeds: {} })
@ -40,7 +41,7 @@ class FeedActions {
if (
feed.type === "feed" &&
feed.errorAt &&
new Date(feed.errorAt).getTime() > Date.now() - 1000 * 60 * 60 * 9
new Date(feed.errorAt).getTime() > Date.now() - distanceTime
) {
feed.errorAt = null
}

View File

@ -36,13 +36,9 @@ class ImageActions {
}
async fetchDimensionsFromDb(images: string[]) {
const dims = [] as StoreImageType[]
for (const image of images) {
const dbData = await getImageDimensionsFromDb(image)
if (dbData) {
dims.push(dbData)
}
}
const dims = (await Promise.all(images.map((image) => getImageDimensionsFromDb(image)))).filter(
Boolean,
) as StoreImageType[]
imageActions.saveImages(dims)
}