1
0
Fork 0
mirror of synced 2024-06-02 02:25:17 +12:00

Merge pull request #8175 from Budibase/fix/remove-app-scans

Removing Redis SCAN operation from app services
This commit is contained in:
Michael Drury 2022-10-07 17:35:05 +01:00 committed by GitHub
commit 7e38e86087
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 17 deletions

View file

@ -214,6 +214,31 @@ export = class RedisWrapper {
}
}
async bulkGet(keys: string[]) {
const db = this._db
const prefixedKeys = keys.map(key => addDbPrefix(db, key))
let response = await this.getClient().mget(prefixedKeys)
if (Array.isArray(response)) {
let final: any = {}
let count = 0
for (let result of response) {
if (result) {
let parsed
try {
parsed = JSON.parse(result)
} catch (err) {
parsed = result
}
final[keys[count]] = parsed
}
count++
}
return final
} else {
throw new Error(`Invalid response: ${response}`)
}
}
async store(key: string, value: any, expirySeconds: number | null = null) {
const db = this._db
if (typeof value === "object") {

View file

@ -32,7 +32,7 @@ const {
import { USERS_TABLE_SCHEMA } from "../../constants"
import { removeAppFromUserRoles } from "../../utilities/workerRequests"
import { clientLibraryPath, stringToReadStream } from "../../utilities"
import { getAllLocks } from "../../utilities/redis"
import { getLocksById } from "../../utilities/redis"
import {
updateClientLibrary,
backupClientLibrary,
@ -45,11 +45,10 @@ import { cleanupAutomations } from "../../automations/utils"
import { context } from "@budibase/backend-core"
import { checkAppMetadata } from "../../automations/logging"
import { getUniqueRows } from "../../utilities/usageQuota/rows"
import { quotas } from "@budibase/pro"
import { quotas, groups } from "@budibase/pro"
import { errors, events, migrations } from "@budibase/backend-core"
import { App, Layout, Screen, MigrationType } from "@budibase/types"
import { BASE_LAYOUT_PROP_IDS } from "../../constants/layouts"
import { groups } from "@budibase/pro"
import { enrichPluginURLs } from "../../utilities/plugins"
const URL_REGEX_SLASH = /\/|\\/g
@ -172,16 +171,16 @@ export const fetch = async (ctx: any) => {
const all = ctx.query && ctx.query.status === AppStatus.ALL
const apps = await getAllApps({ dev, all })
const appIds = apps
.filter((app: any) => app.status === "development")
.map((app: any) => app.appId)
// get the locks for all the dev apps
if (dev || all) {
const locks = await getAllLocks()
const locks = await getLocksById(appIds)
for (let app of apps) {
if (app.status !== "development") {
continue
}
const lock = locks.find((lock: any) => lock.appId === app.appId)
const lock = locks[app.appId]
if (lock) {
app.lockedBy = lock.user
app.lockedBy = lock
} else {
// make sure its definitely not present
delete app.lockedBy

View file

@ -1,7 +1,7 @@
jest.mock("../../../utilities/redis", () => ({
init: jest.fn(),
getAllLocks: () => {
return []
getLocksById: () => {
return {}
},
doesUserHaveLock: () => {
return true

View file

@ -34,12 +34,8 @@ exports.doesUserHaveLock = async (devAppId, user) => {
return expected === userId
}
exports.getAllLocks = async () => {
const locks = await devAppClient.scan()
return locks.map(lock => ({
appId: lock.key,
user: lock.value,
}))
exports.getLocksById = async appIds => {
return await devAppClient.bulkGet(appIds)
}
exports.updateLock = async (devAppId, user) => {