This commit is contained in:
Sam Rose 2024-07-08 13:28:48 +01:00
parent 37d53cff20
commit 1851e11bc0
No known key found for this signature in database
5 changed files with 22 additions and 10 deletions

View File

@ -1,6 +1,8 @@
import { getCouchInfo } from "./connections" import { getCouchInfo } from "./connections"
import fetch from "node-fetch" import fetch from "node-fetch"
import { checkSlashesInUrl } from "../../helpers" import { checkSlashesInUrl } from "../../helpers"
import * as context from "../../context"
import env from "../../environment"
export async function directCouchCall( export async function directCouchCall(
path: string, path: string,
@ -53,3 +55,11 @@ export async function directCouchQuery(
throw "Cannot connect to CouchDB instance" throw "Cannot connect to CouchDB instance"
} }
} }
export function isSqsEnabledForTenant(): boolean {
const tenantId = context.getTenantId()
return (
env.SQS_SEARCH_ENABLE !== undefined &&
env.SQS_SEARCH_ENABLE_TENANTS.includes(tenantId)
)
}

View File

@ -116,6 +116,8 @@ const environment = {
COUCH_DB_URL: process.env.COUCH_DB_URL || "http://localhost:4005", COUCH_DB_URL: process.env.COUCH_DB_URL || "http://localhost:4005",
COUCH_DB_SQL_URL: process.env.COUCH_DB_SQL_URL || "http://localhost:4006", COUCH_DB_SQL_URL: process.env.COUCH_DB_SQL_URL || "http://localhost:4006",
SQS_SEARCH_ENABLE: process.env.SQS_SEARCH_ENABLE, SQS_SEARCH_ENABLE: process.env.SQS_SEARCH_ENABLE,
SQS_SEARCH_ENABLE_TENANTS:
process.env.SQS_SEARCH_ENABLE_TENANTS?.split(",") || [],
COUCH_DB_USERNAME: process.env.COUCH_DB_USER, COUCH_DB_USERNAME: process.env.COUCH_DB_USER,
COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD, COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD,
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID, GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,

View File

@ -15,7 +15,7 @@ import { getViews, saveView } from "../view/utils"
import viewTemplate from "../view/viewBuilder" import viewTemplate from "../view/viewBuilder"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { quotas } from "@budibase/pro" import { quotas } from "@budibase/pro"
import { events, context } from "@budibase/backend-core" import { events, context, db } from "@budibase/backend-core"
import { import {
AutoFieldSubType, AutoFieldSubType,
ContextUser, ContextUser,
@ -324,7 +324,7 @@ class TableSaveFunctions {
importRows: this.importRows, importRows: this.importRows,
user: this.user, user: this.user,
}) })
if (env.SQS_SEARCH_ENABLE) { if (db.isSqsEnabledForTenant()) {
await sdk.tables.sqs.addTable(table) await sdk.tables.sqs.addTable(table)
} }
return table return table
@ -498,16 +498,16 @@ export function setStaticSchemas(datasource: Datasource, table: Table) {
} }
export async function internalTableCleanup(table: Table, rows?: Row[]) { export async function internalTableCleanup(table: Table, rows?: Row[]) {
const db = context.getAppDB() const appDb = context.getAppDB()
const tableId = table._id! const tableId = table._id!
// remove table search index // remove table search index
if (!env.isTest() || env.COUCH_DB_URL) { if (!env.isTest() || env.COUCH_DB_URL) {
const currentIndexes = await db.getIndexes() const currentIndexes = await appDb.getIndexes()
const existingIndex = currentIndexes.indexes.find( const existingIndex = currentIndexes.indexes.find(
(existing: any) => existing.name === `search:${tableId}` (existing: any) => existing.name === `search:${tableId}`
) )
if (existingIndex) { if (existingIndex) {
await db.deleteIndex(existingIndex) await appDb.deleteIndex(existingIndex)
} }
} }
@ -518,7 +518,7 @@ export async function internalTableCleanup(table: Table, rows?: Row[]) {
if (rows) { if (rows) {
await AttachmentCleanup.tableDelete(table, rows) await AttachmentCleanup.tableDelete(table, rows)
} }
if (env.SQS_SEARCH_ENABLE) { if (db.isSqsEnabledForTenant()) {
await sdk.tables.sqs.removeTable(table) await sdk.tables.sqs.removeTable(table)
} }
} }

View File

@ -12,11 +12,11 @@ import * as internal from "./search/internal"
import * as external from "./search/external" import * as external from "./search/external"
import { NoEmptyFilterStrings } from "../../../constants" import { NoEmptyFilterStrings } from "../../../constants"
import * as sqs from "./search/sqs" import * as sqs from "./search/sqs"
import env from "../../../environment"
import { ExportRowsParams, ExportRowsResult } from "./search/types" import { ExportRowsParams, ExportRowsResult } from "./search/types"
import { dataFilters } from "@budibase/shared-core" import { dataFilters } from "@budibase/shared-core"
import sdk from "../../index" import sdk from "../../index"
import { searchInputMapping } from "./search/utils" import { searchInputMapping } from "./search/utils"
import { db } from "@budibase/backend-core"
export { isValidFilter } from "../../../integrations/utils" export { isValidFilter } from "../../../integrations/utils"
@ -115,7 +115,7 @@ export async function search(
if (isExternalTable) { if (isExternalTable) {
return external.search(options, table) return external.search(options, table)
} else if (env.SQS_SEARCH_ENABLE) { } else if (db.isSqsEnabledForTenant()) {
return sqs.search(options, table) return sqs.search(options, table)
} else { } else {
return internal.search(options, table) return internal.search(options, table)

View File

@ -1,4 +1,4 @@
import { context } from "@budibase/backend-core" import { context, db } from "@budibase/backend-core"
import { getTableParams } from "../../../db/utils" import { getTableParams } from "../../../db/utils"
import { import {
breakExternalTableId, breakExternalTableId,
@ -34,7 +34,7 @@ export function processTable(table: Table): Table {
sourceId: table.sourceId || INTERNAL_TABLE_SOURCE_ID, sourceId: table.sourceId || INTERNAL_TABLE_SOURCE_ID,
sourceType: TableSourceType.INTERNAL, sourceType: TableSourceType.INTERNAL,
} }
if (env.SQS_SEARCH_ENABLE) { if (db.isSqsEnabledForTenant()) {
processed.sql = !!env.SQS_SEARCH_ENABLE processed.sql = !!env.SQS_SEARCH_ENABLE
} }
return processed return processed