set the url in redis when an item is inserted into db
This commit is contained in:
@ -15,7 +15,7 @@ import {
|
||||
valuesToRawSql,
|
||||
} from '../repository'
|
||||
import { libraryItemRepository } from '../repository/library_item'
|
||||
import { wordsCount } from '../utils/helpers'
|
||||
import { setRecentlySavedItemInRedis, wordsCount } from '../utils/helpers'
|
||||
import { parseSearchQuery } from '../utils/search'
|
||||
|
||||
enum ReadFilter {
|
||||
@ -818,6 +818,8 @@ export const createLibraryItem = async (
|
||||
userId
|
||||
)
|
||||
|
||||
await setRecentlySavedItemInRedis(userId, newLibraryItem.originalUrl)
|
||||
|
||||
if (skipPubSub) {
|
||||
return newLibraryItem
|
||||
}
|
||||
|
||||
@ -195,14 +195,6 @@ export const savePage = async (
|
||||
}
|
||||
}
|
||||
|
||||
// save the url in redis for 8 hours so rss-feeder won't try to re-save it
|
||||
const redisKey = `recent-saved-item:${user.id}:${itemToSave.originalUrl}`
|
||||
const expireInSeconds = 60 * 60 * 8
|
||||
await redisClient.set(redisKey, 1, {
|
||||
EX: expireInSeconds,
|
||||
NX: true,
|
||||
})
|
||||
|
||||
return {
|
||||
clientRequestId,
|
||||
url: `${homePageURL()}/${user.profile.username}/${slug}`,
|
||||
|
||||
@ -25,6 +25,7 @@ import {
|
||||
SearchItem,
|
||||
} from '../generated/graphql'
|
||||
import { createPubSubClient } from '../pubsub'
|
||||
import { redisClient } from '../redis'
|
||||
import { Claims, WithDataSourcesContext } from '../resolvers/types'
|
||||
import { validateUrl } from '../services/create_page_save_request'
|
||||
import { updateLibraryItem } from '../services/library_item'
|
||||
@ -407,3 +408,16 @@ export const isRelativeUrl = (url: string): boolean => {
|
||||
export const getAbsoluteUrl = (url: string, baseUrl: string): string => {
|
||||
return new URL(url, baseUrl).href
|
||||
}
|
||||
|
||||
export const setRecentlySavedItemInRedis = async (
|
||||
userId: string,
|
||||
url: string
|
||||
) => {
|
||||
// save the url in redis for 8 hours so rss-feeder won't try to re-save it
|
||||
const redisKey = `recent-saved-item:${userId}:${url}`
|
||||
const ttlInSeconds = 60 * 60 * 8
|
||||
return redisClient.set(redisKey, 1, {
|
||||
EX: ttlInSeconds,
|
||||
NX: true,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user