Clean code

This commit is contained in:
Adria Navarro 2024-09-03 10:43:44 +02:00
parent 6d24eba679
commit e61b619740
1 changed files with 6 additions and 5 deletions

View File

@ -1,7 +1,6 @@
import { import {
FieldType, FieldType,
RelationSchemaField, RelationSchemaField,
RelationshipFieldMetadata,
RenameColumn, RenameColumn,
Table, Table,
TableSchema, TableSchema,
@ -255,18 +254,20 @@ export function syncSchema(
} }
export async function renameLinkedViews(table: Table, renaming: RenameColumn) { export async function renameLinkedViews(table: Table, renaming: RenameColumn) {
const relatedLinks: Record<string, RelationshipFieldMetadata[]> = {} const relatedTableIds = new Set<string>()
for (const field of Object.values(table.schema)) { for (const field of Object.values(table.schema)) {
if (field.type !== FieldType.LINK) { if (field.type !== FieldType.LINK) {
continue continue
} }
relatedLinks[field.tableId] ??= [] relatedTableIds.add(field.tableId)
relatedLinks[field.tableId].push(field) break
} }
const relatedTables = await sdk.tables.getTables(Object.keys(relatedLinks)) const relatedTables = await sdk.tables.getTables(
Array.from(relatedTableIds.values())
)
for (const relatedTable of relatedTables) { for (const relatedTable of relatedTables) {
let toSave = false let toSave = false
const viewsV2 = Object.values(relatedTable.views || {}).filter( const viewsV2 = Object.values(relatedTable.views || {}).filter(