Skip to content

Commit fcb9775

Browse files
committed
chore: fix rebase issues and refactor consts
1 parent b977f26 commit fcb9775

File tree

6 files changed

+47
-18
lines changed

6 files changed

+47
-18
lines changed

packages/backend/src/apps/tiles/actions/find-multiple-rows/index.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { IRawAction } from '@plumber/types'
33
import { FOR_EACH_INPUT_SOURCE } from '@/apps/toolbox/common/constants'
44
import StepError from '@/errors/step'
55
import logger from '@/helpers/logger'
6-
import { getTableRows, TableRowFilter } from '@/models/dynamodb/table-row'
76
import Step from '@/models/step'
87
import TableCollaborator from '@/models/table-collaborators'
9-
import TableColumnMetadata from '@/models/table-column-metadata'
8+
import TableMetadata from '@/models/table-metadata'
9+
import { getTableOperations } from '@/models/tiles/factory'
10+
import { TableRowFilter } from '@/models/tiles/types'
1011

1112
import {
1213
FIND_MULTIPLE_ROWS_LIMIT,
@@ -89,13 +90,24 @@ const action: IRawAction = {
8990
/**
9091
* Check for columns first, there will not be any columns if the tile has been deleted.
9192
*/
92-
const columns = await TableColumnMetadata.getColumns(tableId, $)
93+
const table = await TableMetadata.query()
94+
.findById(tableId)
95+
.withGraphFetched('columns')
96+
97+
if (!table) {
98+
throw new StepError(
99+
'Tile not found',
100+
'Tile may have been deleted. Please check your tile.',
101+
$.step.position,
102+
$.app.name,
103+
)
104+
}
93105

94106
await TableCollaborator.hasAccess($.user?.id, tableId, 'editor', $)
95107

96108
// Check that filters are valid
97109
try {
98-
validateFilters(filters, columns)
110+
validateFilters(filters, table.columns)
99111
} catch (e) {
100112
logger.error({
101113
message: 'Invalid filters',
@@ -117,16 +129,18 @@ const action: IRawAction = {
117129
const scanLimitRaw = +step.config?.adminOverride?.tileScanLimit
118130
const scanLimit = isNaN(scanLimitRaw) ? undefined : scanLimitRaw
119131

120-
const { rows } = await getTableRows({
132+
const tableOperations = getTableOperations(table.db)
133+
134+
const { rows } = await tableOperations.getTableRows({
121135
tableId,
122-
columnIds: columns.map((c) => c.id),
136+
columnIds: table.columns.map((c) => c.id),
123137
filters,
124138
order: returnLastRowFirst ? 'desc' : 'asc',
125139
scanLimit,
126140
})
127141

128142
const columnData: TileColumnMetadata[] = []
129-
columns
143+
table.columns
130144
.sort((a, b) => a.position - b.position)
131145
.forEach((c) => {
132146
columnData.push({

packages/backend/src/apps/tiles/common/constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { IFieldVisibilityCondition } from '@plumber/types'
22

3-
import { TableRowFilterOperator } from '@/models/dynamodb/table-row'
3+
import { TableRowFilterOperator } from '@/models/tiles/types'
4+
5+
export const POSTGRES_FIND_ALL_ROWS_PAGINATION_LIMIT = 10000
6+
7+
export const DYNAMODB_DEFAULT_PAGINATION_CURSOR = 'start' as const
48

59
export const FIND_MULTIPLE_ROWS_LIMIT = 500
610

packages/backend/src/graphql/queries/tiles/get-all-rows.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { NotFoundError as ObjectionNotFoundError } from 'objection'
22

3+
import {
4+
DYNAMODB_DEFAULT_PAGINATION_CURSOR,
5+
POSTGRES_FIND_ALL_ROWS_PAGINATION_LIMIT,
6+
} from '@/apps/tiles/common/constants'
37
import { NotFoundError } from '@/errors/graphql-errors/not-found'
48
import { RateLimitedError } from '@/errors/graphql-errors/rate-limited'
59
import InvalidTileViewKeyError from '@/errors/invalid-tile-view-key'
@@ -49,10 +53,13 @@ const getAllRows: QueryResolvers['getAllRows'] = async (
4953
columnIds,
5054
// If table is postgres, we set pagination limit
5155
// If table is dynamodb, the pagination size is based on dynamodb query limits
52-
scanLimit: table.db === 'pg' ? 10000 : undefined,
56+
scanLimit:
57+
table.db === 'pg'
58+
? POSTGRES_FIND_ALL_ROWS_PAGINATION_LIMIT
59+
: undefined,
5360
stringifiedCursor:
5461
table.db === 'ddb' && !stringifiedCursor
55-
? 'start'
62+
? DYNAMODB_DEFAULT_PAGINATION_CURSOR
5663
: stringifiedCursor,
5764
})
5865

packages/backend/src/models/tiles/dynamodb/table-row/functions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type QueryCommandOutput } from '@aws-sdk/client-dynamodb'
22
import { randomUUID } from 'crypto'
33

4+
import { DYNAMODB_DEFAULT_PAGINATION_CURSOR } from '@/apps/tiles/common/constants'
45
import logger from '@/helpers/logger'
56

67
import {
@@ -321,7 +322,7 @@ export const getTableRows = async ({
321322
* if stringifiedCursor is 'start', we will fetch the first page of results
322323
* if undefined, we will auto-paginate
323324
*/
324-
stringifiedCursor?: string | 'start'
325+
stringifiedCursor?: string | typeof DYNAMODB_DEFAULT_PAGINATION_CURSOR
325326
/**
326327
* Optional limit on the total number of rows scanned.
327328
*/
@@ -345,7 +346,8 @@ export const getTableRows = async ({
345346
const tableRows = []
346347
let remainingScanLimit = scanLimit ?? Infinity
347348
let cursor: any =
348-
stringifiedCursor && stringifiedCursor !== 'start'
349+
stringifiedCursor &&
350+
stringifiedCursor !== DYNAMODB_DEFAULT_PAGINATION_CURSOR
349351
? JSON.parse(stringifiedCursor)
350352
: null
351353
do {

packages/backend/src/models/tiles/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { CreateEntityItem } from 'electrodb'
22

3+
import { DYNAMODB_DEFAULT_PAGINATION_CURSOR } from '@/apps/tiles/common/constants'
4+
35
import { TableRow } from './dynamodb/table-row/model'
46

57
export type TableRowItem = CreateEntityItem<typeof TableRow>
@@ -58,7 +60,7 @@ export interface TableOperations {
5860
columnIds?: string[]
5961
filters?: TableRowFilter[]
6062
order?: 'asc' | 'desc'
61-
stringifiedCursor?: string | 'start'
63+
stringifiedCursor?: string | typeof DYNAMODB_DEFAULT_PAGINATION_CURSOR
6264
scanLimit?: number
6365
}): Promise<{
6466
rows: TableRowOutput[]

packages/frontend/src/pages/Tile/components/TableBanner/ImportCsvButton.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ type IMPORT_STATUS =
4747
| 'completed'
4848
| 'error'
4949

50-
// 5 MB in bytes
50+
// 2 MB in bytes for both for now
5151
const MAX_FILE_SIZE = {
52-
[DatabaseType.Pg]: 5 * 1000 * 1000,
52+
[DatabaseType.Pg]: 2 * 1000 * 1000,
5353
[DatabaseType.Ddb]: 2 * 1000 * 1000,
5454
}
5555
// Add row chunk size
56-
const CHUNK_SIZE = {
56+
const IMPORT_CHUNK_SIZE = {
5757
[DatabaseType.Pg]: 1000,
5858
[DatabaseType.Ddb]: 100,
5959
}
@@ -262,7 +262,7 @@ export const ImportCsvModalContent = ({
262262
setImportStatus('importing')
263263
setRowsToImport(mappedData.length)
264264
setRowsImported(0)
265-
const chunkedData = chunk(mappedData, CHUNK_SIZE[databaseType])
265+
const chunkedData = chunk(mappedData, IMPORT_CHUNK_SIZE[databaseType])
266266

267267
for (let i = 0; i < chunkedData.length; i++) {
268268
await createRows({
@@ -276,7 +276,7 @@ export const ImportCsvModalContent = ({
276276
if (i === chunkedData.length - 1 && !onPreImport) {
277277
await refetch()
278278
}
279-
setRowsImported((i + 1) * CHUNK_SIZE[databaseType])
279+
setRowsImported((i + 1) * IMPORT_CHUNK_SIZE[databaseType])
280280
}
281281
}
282282
setImportStatus('completed')

0 commit comments

Comments
 (0)