mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
check if there are more than five items "created" within a minute instead of "saved"
This commit is contained in:
parent
31fe4b65a0
commit
6776cdf1cd
2 changed files with 10 additions and 5 deletions
|
|
@ -8,11 +8,10 @@ import {
|
|||
PageType,
|
||||
} from '../generated/graphql'
|
||||
import { createPubSubClient, PubsubClient } from '../pubsub'
|
||||
import { Merge } from '../util'
|
||||
import { enqueueParseRequest } from '../utils/createTask'
|
||||
import { cleanUrl, generateSlug } from '../utils/helpers'
|
||||
import { logger } from '../utils/logger'
|
||||
import { countBySavedAt, createOrUpdateLibraryItem } from './library_item'
|
||||
import { countByCreatedAt, createOrUpdateLibraryItem } from './library_item'
|
||||
|
||||
interface PageSaveRequest {
|
||||
user: User
|
||||
|
|
@ -39,7 +38,13 @@ const isPrivateIP = privateIpLib.default
|
|||
const getPriorityByRateLimit = async (
|
||||
userId: string
|
||||
): Promise<'low' | 'high'> => {
|
||||
const count = await countBySavedAt(userId, new Date(Date.now() - 60 * 1000))
|
||||
const now = new Date()
|
||||
const count = await countByCreatedAt(
|
||||
userId,
|
||||
new Date(now.getTime() - 60 * 1000), // 1 minute ago
|
||||
now
|
||||
)
|
||||
|
||||
return count >= 5 ? 'low' : 'high'
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1192,7 +1192,7 @@ export const findLibraryItemsByPrefix = async (
|
|||
)
|
||||
}
|
||||
|
||||
export const countBySavedAt = async (
|
||||
export const countByCreatedAt = async (
|
||||
userId: string,
|
||||
startDate = new Date(0),
|
||||
endDate = new Date()
|
||||
|
|
@ -1202,7 +1202,7 @@ export const countBySavedAt = async (
|
|||
tx
|
||||
.createQueryBuilder(LibraryItem, 'library_item')
|
||||
.where('library_item.user_id = :userId', { userId })
|
||||
.andWhere('library_item.saved_at between :startDate and :endDate', {
|
||||
.andWhere('library_item.created_at between :startDate and :endDate', {
|
||||
startDate,
|
||||
endDate,
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue