update refreshed_at when feed is processed

This commit is contained in:
Hongbo Wu 2024-01-24 12:12:26 +08:00
parent 68a4fb298d
commit 3cb7c38e7f
5 changed files with 23 additions and 15 deletions

View file

@ -2839,8 +2839,10 @@ export type Subscription = {
id: Scalars['ID'];
isPrivate?: Maybe<Scalars['Boolean']>;
lastFetchedAt?: Maybe<Scalars['Date']>;
mostRecentItemDate?: Maybe<Scalars['Date']>;
name: Scalars['String'];
newsletterEmail?: Maybe<Scalars['String']>;
refreshedAt?: Maybe<Scalars['Date']>;
status: SubscriptionStatus;
type: SubscriptionType;
unsubscribeHttpUrl?: Maybe<Scalars['String']>;
@ -3210,9 +3212,10 @@ export type UpdateSubscriptionInput = {
folder?: InputMaybe<Scalars['String']>;
id: Scalars['ID'];
isPrivate?: InputMaybe<Scalars['Boolean']>;
lastFetchedAt?: InputMaybe<Scalars['Date']>;
lastFetchedChecksum?: InputMaybe<Scalars['String']>;
mostRecentItemDate?: InputMaybe<Scalars['Date']>;
name?: InputMaybe<Scalars['String']>;
refreshedAt?: InputMaybe<Scalars['Date']>;
scheduledAt?: InputMaybe<Scalars['Date']>;
status?: InputMaybe<SubscriptionStatus>;
};
@ -6193,8 +6196,10 @@ export type SubscriptionResolvers<ContextType = ResolverContext, ParentType exte
id?: SubscriptionResolver<ResolversTypes['ID'], "id", ParentType, ContextType>;
isPrivate?: SubscriptionResolver<Maybe<ResolversTypes['Boolean']>, "isPrivate", ParentType, ContextType>;
lastFetchedAt?: SubscriptionResolver<Maybe<ResolversTypes['Date']>, "lastFetchedAt", ParentType, ContextType>;
mostRecentItemDate?: SubscriptionResolver<Maybe<ResolversTypes['Date']>, "mostRecentItemDate", ParentType, ContextType>;
name?: SubscriptionResolver<ResolversTypes['String'], "name", ParentType, ContextType>;
newsletterEmail?: SubscriptionResolver<Maybe<ResolversTypes['String']>, "newsletterEmail", ParentType, ContextType>;
refreshedAt?: SubscriptionResolver<Maybe<ResolversTypes['Date']>, "refreshedAt", ParentType, ContextType>;
status?: SubscriptionResolver<ResolversTypes['SubscriptionStatus'], "status", ParentType, ContextType>;
type?: SubscriptionResolver<ResolversTypes['SubscriptionType'], "type", ParentType, ContextType>;
unsubscribeHttpUrl?: SubscriptionResolver<Maybe<ResolversTypes['String']>, "unsubscribeHttpUrl", ParentType, ContextType>;

View file

@ -2235,8 +2235,10 @@ type Subscription {
id: ID!
isPrivate: Boolean
lastFetchedAt: Date
mostRecentItemDate: Date
name: String!
newsletterEmail: String
refreshedAt: Date
status: SubscriptionStatus!
type: SubscriptionType!
unsubscribeHttpUrl: String
@ -2577,9 +2579,10 @@ input UpdateSubscriptionInput {
folder: String
id: ID!
isPrivate: Boolean
lastFetchedAt: Date
lastFetchedChecksum: String
mostRecentItemDate: Date
name: String
refreshedAt: Date
scheduledAt: Date
status: SubscriptionStatus
}

View file

@ -6,9 +6,9 @@ import Parser, { Item } from 'rss-parser'
import { promisify } from 'util'
import { env } from '../../env'
import { redisDataSource } from '../../redis_data_source'
import { updateSubscription } from '../../services/update_subscription'
import createHttpTaskWithToken from '../../utils/createTask'
import { RSSRefreshContext } from './refreshAllFeeds'
import { updateSubscription } from '../../services/update_subscription'
type FolderType = 'following' | 'inbox'
@ -429,6 +429,8 @@ const processSubscription = async (
folder: FolderType,
feed: RssFeed
) => {
const refreshedAt = new Date()
let lastItemFetchedAt: Date | null = null
let lastValidItem: RssFeedItem | null = null
@ -549,11 +551,12 @@ const processSubscription = async (
const updatePeriodInMs = getUpdatePeriodInHours(feed) * 60 * 60 * 1000
const nextScheduledAt = scheduledAt + updatePeriodInMs * updateFrequency
// update subscription lastFetchedAt
// update subscription mostRecentItemDate and refreshedAt
const updatedSubscription = await updateSubscription(userId, subscriptionId, {
lastFetchedAt: lastItemFetchedAt,
mostRecentItemDate: lastItemFetchedAt,
lastFetchedChecksum: updatedLastFetchedChecksum,
scheduledAt: new Date(nextScheduledAt),
refreshedAt,
})
console.log('Updated subscription', updatedSubscription)
}

View file

@ -2600,7 +2600,6 @@ const schema = gql`
id: ID!
name: String
description: String
lastFetchedAt: Date
lastFetchedChecksum: String
status: SubscriptionStatus
scheduledAt: Date
@ -2608,6 +2607,8 @@ const schema = gql`
autoAddToLibrary: Boolean
fetchContent: Boolean
folder: String
refreshedAt: Date
mostRecentItemDate: Date
}
union UpdateSubscriptionResult =

View file

@ -1,8 +1,4 @@
import { Subscription } from '../entity/subscription'
import {
SubscriptionStatus,
UpdateSubscriptionInput,
} from '../generated/graphql'
import { Subscription, SubscriptionStatus } from '../entity/subscription'
import { getRepository } from '../repository'
const ensureOwns = async (userId: string, subscriptionId: string) => {
@ -23,11 +19,12 @@ type UpdateSubscriptionData = {
fetchContent?: boolean | null
folder?: string | null
isPrivate?: boolean | null
lastFetchedAt?: Date | null
mostRecentItemDate?: Date | null
lastFetchedChecksum?: string | null
name?: string | null
scheduledAt?: Date | null
status?: SubscriptionStatus | null
refreshedAt?: Date | null
}
export const updateSubscription = async (
@ -42,9 +39,8 @@ export const updateSubscription = async (
id: subscriptionId,
name: newData.name || undefined,
description: newData.description || undefined,
lastFetchedAt: newData.lastFetchedAt
? new Date(newData.lastFetchedAt)
: undefined,
mostRecentItemDate: newData.mostRecentItemDate || undefined,
refreshedAt: newData.refreshedAt || undefined,
lastFetchedChecksum: newData.lastFetchedChecksum || undefined,
status: newData.status || undefined,
scheduledAt: newData.scheduledAt