forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FTR]
KbnClientSavedObjects
improvements (elastic#149582)
## Summary Follow-up of elastic#149188 - Use the bulkDelete API for `KbnClientSavedObjects.bulkDelete` - Create a dedicated `/_clean` endpoint for `KbnClientSavedObjects.clean` and `KbnClientSavedObjects.cleanStandardList` --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
82ef3e1
commit 98e8a41
Showing
8 changed files
with
231 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { IRouter } from '@kbn/core/server'; | ||
import { schema } from '@kbn/config-schema'; | ||
import { KBN_CLIENT_API_PREFIX, listHiddenTypes, catchAndReturnBoomErrors } from './utils'; | ||
|
||
export const registerCleanRoute = (router: IRouter) => { | ||
router.post( | ||
{ | ||
path: `${KBN_CLIENT_API_PREFIX}/_clean`, | ||
options: { | ||
tags: ['access:ftrApis'], | ||
}, | ||
validate: { | ||
body: schema.object({ | ||
types: schema.arrayOf(schema.string()), | ||
}), | ||
}, | ||
}, | ||
catchAndReturnBoomErrors(async (ctx, req, res) => { | ||
const { types } = req.body; | ||
const { savedObjects } = await ctx.core; | ||
const hiddenTypes = listHiddenTypes(savedObjects.typeRegistry); | ||
const soClient = savedObjects.getClient({ includedHiddenTypes: hiddenTypes }); | ||
|
||
const finder = soClient.createPointInTimeFinder({ type: types, perPage: 100 }); | ||
let deleted = 0; | ||
|
||
for await (const response of finder.find()) { | ||
const objects = response.saved_objects.map(({ type, id }) => ({ type, id })); | ||
const { statuses } = await soClient.bulkDelete(objects, { force: true }); | ||
deleted += statuses.filter((status) => status.success).length; | ||
} | ||
|
||
return res.ok({ | ||
body: { | ||
deleted, | ||
}, | ||
}); | ||
}) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.