@backstage/plugin-catalog-backend 1.9.1-next.1 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # @backstage/plugin-catalog-backend
2
2
 
3
+ ## 1.9.1
4
+
5
+ ### Patch Changes
6
+
7
+ - ce8d203235b: Ensure that entity cache state is only written to the database when actually changed
8
+ - 485a6c5f7b5: Internal refactoring for performance in the service handlers
9
+ - 3587a968dcd: Fixed a bug in the `queryEntities` endpoint that was causing filtered entities to be included in cursor requests.
10
+ - ce335df9d1c: Improve the query for orphan pruning
11
+ - 27956d78671: Adjusted the OpenAPI schema file name according to the new structure
12
+ - 51064e6e5ee: Change orphan cleanup task to only log a message if it deleted entities.
13
+ - 12a345317ab: Remove unnecessary join in the entity facets endpoint, exclude nulls
14
+ - Updated dependencies
15
+ - @backstage/backend-common@0.18.5
16
+ - @backstage/integration@1.4.5
17
+ - @backstage/plugin-scaffolder-common@1.3.0
18
+ - @backstage/plugin-permission-node@0.7.8
19
+ - @backstage/backend-tasks@0.5.2
20
+ - @backstage/plugin-catalog-node@1.3.6
21
+ - @backstage/plugin-search-backend-module-catalog@0.1.1
22
+ - @backstage/backend-plugin-api@0.5.2
23
+ - @backstage/catalog-client@1.4.1
24
+ - @backstage/catalog-model@1.3.0
25
+ - @backstage/config@1.0.7
26
+ - @backstage/errors@1.1.5
27
+ - @backstage/types@1.0.2
28
+ - @backstage/plugin-catalog-common@1.0.13
29
+ - @backstage/plugin-permission-common@0.7.5
30
+ - @backstage/plugin-search-common@1.2.3
31
+
32
+ ## 1.9.1-next.2
33
+
34
+ ### Patch Changes
35
+
36
+ - ce8d203235b: Ensure that entity cache state is only written to the database when actually changed
37
+ - 485a6c5f7b5: Internal refactoring for performance in the service handlers
38
+ - 3587a968dcd: Fixed a bug in the `queryEntities` endpoint that was causing filtered entities to be included in cursor requests.
39
+ - 12a345317ab: Remove unnecessary join in the entity facets endpoint, exclude nulls
40
+ - Updated dependencies
41
+ - @backstage/plugin-scaffolder-common@1.3.0-next.0
42
+ - @backstage/config@1.0.7
43
+
3
44
  ## 1.9.1-next.1
4
45
 
5
46
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-backend",
3
- "version": "1.9.1-next.1",
3
+ "version": "1.9.1",
4
4
  "main": "../dist/alpha.cjs.js",
5
5
  "types": "../dist/alpha.d.ts"
6
6
  }
package/dist/alpha.cjs.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var alpha = require('@backstage/plugin-catalog-common/alpha');
6
6
  var pluginPermissionNode = require('@backstage/plugin-permission-node');
7
- var CatalogBuilder = require('./cjs/CatalogBuilder-ecfd2db6.cjs.js');
7
+ var CatalogBuilder = require('./cjs/CatalogBuilder-6a9091b7.cjs.js');
8
8
  var backendPluginApi = require('@backstage/backend-plugin-api');
9
9
  var alpha$1 = require('@backstage/plugin-catalog-node/alpha');
10
10
  var backendCommon = require('@backstage/backend-common');
@@ -1177,10 +1177,12 @@ async function deleteOrphanedEntities(options) {
1177
1177
  for (let i = 0; i < 100; ++i) {
1178
1178
  const candidates = await tx.with(
1179
1179
  "orphans",
1180
- (orphans) => orphans.from("refresh_state").select("entity_id", "entity_ref").whereNotIn(
1181
- "entity_ref",
1182
- (keep) => keep.distinct("target_entity_ref").from("refresh_state_references")
1183
- )
1180
+ ["entity_id", "entity_ref"],
1181
+ (orphans) => orphans.from("refresh_state").select("refresh_state.entity_id", "refresh_state.entity_ref").leftOuterJoin(
1182
+ "refresh_state_references",
1183
+ "refresh_state_references.target_entity_ref",
1184
+ "refresh_state.entity_ref"
1185
+ ).whereNull("refresh_state_references.target_entity_ref")
1184
1186
  ).select({
1185
1187
  entityId: "orphans.entity_id",
1186
1188
  relationSourceId: "refresh_state.entity_id"
@@ -1563,7 +1565,8 @@ class DefaultCatalogProcessingEngine {
1563
1565
  });
1564
1566
  track.markProcessorsCompleted(result);
1565
1567
  if (result.ok) {
1566
- if (stableStringify__default["default"](state) !== stableStringify__default["default"](result.state)) {
1568
+ const { ttl: _, ...stateWithoutTtl } = state != null ? state : {};
1569
+ if (stableStringify__default["default"](stateWithoutTtl) !== stableStringify__default["default"](result.state)) {
1567
1570
  await this.processingDatabase.transaction(async (tx) => {
1568
1571
  await this.processingDatabase.updateEntityCache(tx, {
1569
1572
  id,
@@ -1696,7 +1699,9 @@ class DefaultCatalogProcessingEngine {
1696
1699
  try {
1697
1700
  await this.processingDatabase.transaction(async (tx) => {
1698
1701
  const n = await this.processingDatabase.deleteOrphanedEntities(tx);
1699
- this.logger.info(`Deleted ${n} orphaned entities`);
1702
+ if (n > 0) {
1703
+ this.logger.info(`Deleted ${n} orphaned entities`);
1704
+ }
1700
1705
  });
1701
1706
  } catch (error) {
1702
1707
  this.logger.warn(`Failed to delete orphaned entities`, error);
@@ -2018,46 +2023,45 @@ function parsePagination(input) {
2018
2023
  return {};
2019
2024
  }
2020
2025
  let { limit, offset } = input;
2021
- if (input.after !== void 0) {
2022
- let cursor;
2023
- try {
2024
- const json = Buffer.from(input.after, "base64").toString("utf8");
2025
- cursor = JSON.parse(json);
2026
- } catch {
2027
- throw new errors.InputError("Malformed after cursor, could not be parsed");
2028
- }
2029
- if (cursor.limit !== void 0) {
2030
- if (!Number.isInteger(cursor.limit)) {
2031
- throw new errors.InputError("Malformed after cursor, limit was not an number");
2032
- }
2033
- limit = cursor.limit;
2026
+ if (input.after === void 0) {
2027
+ return { limit, offset };
2028
+ }
2029
+ let cursor;
2030
+ try {
2031
+ const json = Buffer.from(input.after, "base64").toString("utf8");
2032
+ cursor = JSON.parse(json);
2033
+ } catch {
2034
+ throw new errors.InputError("Malformed after cursor, could not be parsed");
2035
+ }
2036
+ if (cursor.limit !== void 0) {
2037
+ if (!Number.isInteger(cursor.limit)) {
2038
+ throw new errors.InputError("Malformed after cursor, limit was not an number");
2034
2039
  }
2035
- if (cursor.offset !== void 0) {
2036
- if (!Number.isInteger(cursor.offset)) {
2037
- throw new errors.InputError("Malformed after cursor, offset was not a number");
2038
- }
2039
- offset = cursor.offset;
2040
+ limit = cursor.limit;
2041
+ }
2042
+ if (cursor.offset !== void 0) {
2043
+ if (!Number.isInteger(cursor.offset)) {
2044
+ throw new errors.InputError("Malformed after cursor, offset was not a number");
2040
2045
  }
2046
+ offset = cursor.offset;
2041
2047
  }
2042
2048
  return { limit, offset };
2043
2049
  }
2044
2050
  function stringifyPagination(input) {
2045
- const json = JSON.stringify({ limit: input.limit, offset: input.offset });
2051
+ const { limit, offset } = input;
2052
+ const json = JSON.stringify({ limit, offset });
2046
2053
  const base64 = Buffer.from(json, "utf8").toString("base64");
2047
2054
  return base64;
2048
2055
  }
2049
2056
  function addCondition(queryBuilder, db, filter, negate = false, entityIdField = "entity_id") {
2050
- const matchQuery = db("search").select("search.entity_id").where({ key: filter.key.toLowerCase() }).andWhere(function keyFilter() {
2051
- if (filter.values) {
2052
- if (filter.values.length === 1) {
2053
- this.where({ value: filter.values[0].toLowerCase() });
2054
- } else {
2055
- this.andWhere(
2056
- "value",
2057
- "in",
2058
- filter.values.map((v) => v.toLowerCase())
2059
- );
2060
- }
2057
+ var _a;
2058
+ const key = filter.key.toLowerCase();
2059
+ const values = (_a = filter.values) == null ? void 0 : _a.map((v) => v.toLowerCase());
2060
+ const matchQuery = db("search").select("search.entity_id").where({ key }).andWhere(function keyFilter() {
2061
+ if ((values == null ? void 0 : values.length) === 1) {
2062
+ this.where({ value: values.at(0) });
2063
+ } else if (values) {
2064
+ this.andWhere("value", "in", values);
2061
2065
  }
2062
2066
  });
2063
2067
  queryBuilder.andWhere(entityIdField, negate ? "not in" : "in", matchQuery);
@@ -2072,14 +2076,14 @@ function isNegationEntityFilter(filter) {
2072
2076
  return filter.hasOwnProperty("not");
2073
2077
  }
2074
2078
  function parseFilter(filter, query, db, negate = false, entityIdField = "entity_id") {
2079
+ if (isNegationEntityFilter(filter)) {
2080
+ return parseFilter(filter.not, query, db, !negate, entityIdField);
2081
+ }
2075
2082
  if (isEntitiesSearchFilter(filter)) {
2076
2083
  return query.andWhere(function filterFunction() {
2077
2084
  addCondition(this, db, filter, negate, entityIdField);
2078
2085
  });
2079
2086
  }
2080
- if (isNegationEntityFilter(filter)) {
2081
- return parseFilter(filter.not, query, db, !negate, entityIdField);
2082
- }
2083
2087
  return query[negate ? "andWhereNot" : "andWhere"](function filterFunction() {
2084
2088
  var _a, _b;
2085
2089
  if (isOrEntityFilter(filter)) {
@@ -2256,13 +2260,12 @@ class DefaultEntitiesCatalog {
2256
2260
  const countQuery = dbQuery.clone();
2257
2261
  const isOrderingDescending = sortField.order === "desc";
2258
2262
  if (prevItemOrderFieldValue) {
2259
- dbQuery.andWhere(
2260
- "value",
2261
- isFetchingBackwards !== isOrderingDescending ? "<" : ">",
2262
- prevItemOrderFieldValue
2263
- );
2264
- dbQuery.orWhere(function nested() {
2265
- this.where("value", "=", prevItemOrderFieldValue).andWhere(
2263
+ dbQuery.andWhere(function nested() {
2264
+ this.where(
2265
+ "value",
2266
+ isFetchingBackwards !== isOrderingDescending ? "<" : ">",
2267
+ prevItemOrderFieldValue
2268
+ ).orWhere("value", "=", prevItemOrderFieldValue).andWhere(
2266
2269
  "search.entity_id",
2267
2270
  isFetchingBackwards !== isOrderingDescending ? "<" : ">",
2268
2271
  prevItemUid
@@ -2416,7 +2419,7 @@ class DefaultEntitiesCatalog {
2416
2419
  const facets = {};
2417
2420
  const db = this.database;
2418
2421
  for (const facet of request.facets) {
2419
- const dbQuery = db("search").join("final_entities", "search.entity_id", "final_entities.entity_id").where("search.key", facet.toLocaleLowerCase("en-US")).count("search.entity_id as count").select({ value: "search.original_value" }).groupBy("search.original_value");
2422
+ const dbQuery = db("search").where("search.key", facet.toLocaleLowerCase("en-US")).whereNotNull("search.original_value").select({ value: "search.original_value", count: db.raw("count(*)") }).groupBy("search.original_value");
2420
2423
  if (request == null ? void 0 : request.filter) {
2421
2424
  parseFilter(request.filter, dbQuery, db, false, "search.entity_id");
2422
2425
  }
@@ -5056,4 +5059,4 @@ exports.createCatalogPermissionRule = createCatalogPermissionRule;
5056
5059
  exports.createRandomProcessingInterval = createRandomProcessingInterval;
5057
5060
  exports.parseEntityYaml = parseEntityYaml;
5058
5061
  exports.permissionRules = permissionRules;
5059
- //# sourceMappingURL=CatalogBuilder-ecfd2db6.cjs.js.map
5062
+ //# sourceMappingURL=CatalogBuilder-6a9091b7.cjs.js.map