Track as different documents

This commit is contained in:
Adria Navarro 2025-03-19 20:09:58 +01:00
parent cb88465f42
commit 4b807aa88b
3 changed files with 11 additions and 5 deletions

View File

@ -124,3 +124,7 @@ export const generateDevInfoID = (userId: string) => {
export const generatePluginID = (name: string) => {
return `${DocumentType.PLUGIN}${SEPARATOR}${name}`
}
export const generateOAuth2LogID = (id: string) => {
return `${DocumentType.OAUTH2_CONFIG_LOG}${SEPARATOR}${id}`
}

View File

@ -1,8 +1,8 @@
import fetch, { RequestInit } from "node-fetch"
import { HttpError } from "koa"
import { get } from "../oauth2"
import { DocumentType, OAuth2CredentialsMethod } from "@budibase/types"
import { cache, context } from "@budibase/backend-core"
import { OAuth2CredentialsMethod } from "@budibase/types"
import { cache, context, docIds } from "@budibase/backend-core"
const { DocWritethrough } = cache.docWritethrough
@ -46,9 +46,11 @@ async function fetchToken(config: {
const trackUsage = async (id: string) => {
const writethrough = new DocWritethrough(
context.getAppDB(),
DocumentType.OAUTH2_CONFIG_USAGES
docIds.generateOAuth2LogID(id)
)
await writethrough.patch({ [id]: Date.now() })
await writethrough.patch({
lastUsage: Date.now(),
})
}
// TODO: check if caching is worth

View File

@ -41,7 +41,7 @@ export enum DocumentType {
SCIM_LOG = "scimlog",
ROW_ACTIONS = "ra",
OAUTH2_CONFIG = "oauth2",
OAUTH2_CONFIG_USAGES = "oauth2_usage",
OAUTH2_CONFIG_LOG = "oauth2_log",
}
// Because DocumentTypes can overlap, we need to make sure that we search