Track as different documents
This commit is contained in:
parent
cb88465f42
commit
4b807aa88b
|
@ -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}`
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue