1
0
Fork 0
mirror of synced 2024-07-07 07:15:43 +12:00

Merge pull request #11245 from Budibase/BUDI-7189/clean_controller_dependencies

Clean controller dependencies
This commit is contained in:
Adria Navarro 2023-07-17 14:17:42 +01:00 committed by GitHub
commit 9ca2848c05
4 changed files with 26 additions and 31 deletions

View file

@ -2,7 +2,6 @@ import * as linkRows from "../../../db/linkedRows"
import {
generateRowID,
getTableIDFromRowID,
DocumentType,
InternalTables,
} from "../../../db/utils"
import * as userController from "../user"
@ -13,14 +12,6 @@ import {
} from "../../../utilities/rowProcessor"
import { FieldTypes } from "../../../constants"
import * as utils from "./utils"
import * as inMemoryViews from "../../../db/inMemoryView"
import env from "../../../environment"
import {
migrateToInMemoryView,
migrateToDesignView,
getFromDesignDoc,
getFromMemoryDoc,
} from "../view/utils"
import { cloneDeep } from "lodash/fp"
import { context, db as dbCore } from "@budibase/backend-core"
import { finaliseRow, updateRelatedFormula } from "./staticFormula"

View file

@ -7,21 +7,7 @@ import { Ctx, UserCtx } from "@budibase/types"
import sdk from "../../sdk"
export async function fetchMetadata(ctx: Ctx) {
const global = await getGlobalUsers()
const metadata = await sdk.users.rawUserMetadata()
const users = []
for (let user of global) {
// find the metadata that matches up to the global ID
const info = metadata.find(meta => meta._id.includes(user._id))
// remove these props, not for the correct DB
users.push({
...user,
...info,
tableId: InternalTables.USER_METADATA,
// make sure the ID is always a local ID, not a global one
_id: generateUserMetadataID(user._id),
})
}
const users = await sdk.users.fetchMetadata()
ctx.body = users
}

View file

@ -8,7 +8,7 @@ import {
} from "../../../../db/utils"
import { getGlobalUsersFromMetadata } from "../../../../utilities/global"
import { outputProcessing } from "../../../../utilities/rowProcessor"
import { Ctx, Database, Row, UserCtx } from "@budibase/types"
import { Ctx, Database, Row } from "@budibase/types"
import { cleanExportRows } from "../utils"
import {
Format,
@ -17,7 +17,6 @@ import {
jsonWithSchema,
} from "../../../../api/controllers/view/exporters"
import { apiFileReturn } from "../../../../utilities/fileSystem"
import * as userController from "../../../../api/controllers/user"
import * as inMemoryViews from "../../../../db/inMemoryView"
import {
migrateToInMemoryView,
@ -25,6 +24,7 @@ import {
getFromDesignDoc,
getFromMemoryDoc,
} from "../../../../api/controllers/view/utils"
import sdk from "../../../../sdk"
export async function search(ctx: Ctx) {
// Fetch the whole table when running in cypress, as search doesn't work
@ -126,15 +126,14 @@ export async function fetch(ctx: Ctx) {
const tableId = ctx.params.tableId
let table = await db.get(tableId)
let rows = await getRawTableData(ctx, db, tableId)
let rows = await getRawTableData(db, tableId)
return outputProcessing(table, rows)
}
async function getRawTableData(ctx: Ctx, db: Database, tableId: string) {
async function getRawTableData(db: Database, tableId: string) {
let rows
if (tableId === InternalTables.USER_METADATA) {
await userController.fetchMetadata(ctx)
rows = ctx.body
rows = await sdk.users.fetchMetadata()
} else {
const response = await db.allDocs(
getRowParams(tableId, null, {
@ -166,7 +165,7 @@ export async function fetchView(ctx: Ctx) {
})
} else {
const tableId = viewInfo.meta.tableId
const data = await getRawTableData(ctx, db, tableId)
const data = await getRawTableData(db, tableId)
response = await inMemoryViews.runView(
viewInfo,
calculation as string,

View file

@ -64,6 +64,25 @@ export async function rawUserMetadata(db?: Database) {
).rows.map(row => row.doc)
}
export async function fetchMetadata() {
const global = await getGlobalUsers()
const metadata = await rawUserMetadata()
const users = []
for (let user of global) {
// find the metadata that matches up to the global ID
const info = metadata.find(meta => meta._id.includes(user._id))
// remove these props, not for the correct DB
users.push({
...user,
...info,
tableId: InternalTables.USER_METADATA,
// make sure the ID is always a local ID, not a global one
_id: generateUserMetadataID(user._id),
})
}
return users
}
export async function syncGlobalUsers() {
// sync user metadata
const dbs = [context.getDevAppDB(), context.getProdAppDB()]