-
Notifications
You must be signed in to change notification settings - Fork 27
Add filters to deleteEntry #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
9a4cf14
12bebf3
0d8607a
631023d
a6737a4
10c0156
68d967b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import {z} from 'zod'; | ||
|
|
||
| export const queryStringArray = () => { | ||
| return z | ||
| .union([z.string(), z.array(z.string())]) | ||
| .transform((val) => (typeof val === 'string' ? [val] : val)); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,18 @@ import {AppError} from '@gravity-ui/nodekit'; | |
| import {transaction} from 'objection'; | ||
|
|
||
| import {makeSchemaValidator} from '../../../components/validation-schema-compiler'; | ||
| import {BiTrackingLogs, DEFAULT_QUERY_TIMEOUT, RETURN_COLUMNS, US_ERRORS} from '../../../const'; | ||
| import { | ||
| ALLOWED_SCOPE_VALUES, | ||
| BiTrackingLogs, | ||
| DEFAULT_QUERY_TIMEOUT, | ||
| RETURN_COLUMNS, | ||
| US_ERRORS, | ||
| } from '../../../const'; | ||
| import Entry from '../../../db/models/entry'; | ||
| import Lock from '../../../db/models/lock'; | ||
| import {EntryColumn} from '../../../db/models/new/entry'; | ||
| import {WorkbookPermission} from '../../../entities/workbook'; | ||
| import {DlsActions, EntryColumns, UsPermissions} from '../../../types/models'; | ||
| import {DlsActions, EntryColumns, EntryScope, UsPermissions} from '../../../types/models'; | ||
| import Utils, {makeUserId} from '../../../utils'; | ||
| import {ServiceArgs} from '../../new/types'; | ||
| import {getWorkbook} from '../../new/workbook/get-workbook'; | ||
|
|
@@ -28,20 +35,32 @@ const validateArgs = makeSchemaValidator({ | |
| useLegacyLogin: { | ||
| type: 'boolean', | ||
| }, | ||
| scope: { | ||
| type: 'string', | ||
| enum: ALLOWED_SCOPE_VALUES, | ||
| }, | ||
| types: { | ||
| type: 'array', | ||
| items: { | ||
| type: 'string', | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export type DeleteEntryData = { | ||
| entryId: string; | ||
| lockToken?: string; | ||
| useLegacyLogin?: boolean; | ||
| scope?: EntryScope; | ||
| types?: string[]; | ||
| }; | ||
|
|
||
| export async function deleteEntry( | ||
| {ctx, skipValidation = false}: ServiceArgs, | ||
| args: DeleteEntryData, | ||
| ) { | ||
| const {entryId, lockToken, useLegacyLogin = false} = args; | ||
| const {entryId, lockToken, useLegacyLogin = false, scope, types} = args; | ||
|
|
||
| ctx.log('DELETE_ENTRY_REQUEST', { | ||
| entryId: Utils.encodeId(entryId), | ||
|
|
@@ -66,6 +85,15 @@ export async function deleteEntry( | |
| entryId, | ||
| isDeleted: false, | ||
| }) | ||
| .where((builder) => { | ||
| if (scope) { | ||
| builder.andWhere({[`${Entry.tableName}.${EntryColumn.Scope}`]: scope}); | ||
| } | ||
|
|
||
| if (types) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it work good without index on entries.type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes index scan on entryId and then filters the result, it's 1 row maximum https://explain.tensor.ru/archive/explain/69ee14e376c7bbf98863ee3c2327e878:0:2025-09-16 |
||
| builder.whereIn([`${Entry.tableName}.${EntryColumn.Type}`], types); | ||
| } | ||
| }) | ||
| .first() | ||
| .timeout(DEFAULT_QUERY_TIMEOUT); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not the best naming, but I couldn't think of anything
maybe just stringArray?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GPT offers stringArrayCoerce
but I wouldn't understand that:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add min, max options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed