Merge pull request #2750 from spotify/freben/no-prefix-search
fix(catalog-backend): remove prefix searching
This commit is contained in:
@@ -90,7 +90,7 @@ export class DatabaseEntitiesCatalog implements EntitiesCatalog {
|
||||
const colocatedEntities = location
|
||||
? await this.database.entities(tx, [
|
||||
{
|
||||
key: LOCATION_ANNOTATION,
|
||||
key: `metadata.annotations.${LOCATION_ANNOTATION}`,
|
||||
values: [location],
|
||||
},
|
||||
])
|
||||
|
||||
@@ -125,46 +125,7 @@ describe('search', () => {
|
||||
},
|
||||
{ entity_id: 'eid', key: 'apiversion', value: 'a' },
|
||||
{ entity_id: 'eid', key: 'kind', value: 'b' },
|
||||
{ entity_id: 'eid', key: 'name', value: 'n' },
|
||||
{ entity_id: 'eid', key: 'namespace', value: null },
|
||||
{ entity_id: 'eid', key: 'uid', value: null },
|
||||
{ entity_id: 'eid', key: 'namespace', value: ENTITY_DEFAULT_NAMESPACE },
|
||||
]);
|
||||
});
|
||||
|
||||
it('adds prefix-stripped versions', () => {
|
||||
const input: Entity = {
|
||||
apiVersion: 'a',
|
||||
kind: 'b',
|
||||
metadata: {
|
||||
name: 'name',
|
||||
labels: {
|
||||
lbl: 'lbl',
|
||||
},
|
||||
annotations: {
|
||||
ann: 'ann',
|
||||
},
|
||||
},
|
||||
spec: {
|
||||
sub: {
|
||||
spc: 'spc',
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(buildEntitySearch('eid', input)).toStrictEqual(
|
||||
expect.arrayContaining([
|
||||
{ entity_id: 'eid', key: 'metadata.name', value: 'name' },
|
||||
{ entity_id: 'eid', key: 'name', value: 'name' },
|
||||
{ entity_id: 'eid', key: 'metadata.labels.lbl', value: 'lbl' },
|
||||
{ entity_id: 'eid', key: 'labels.lbl', value: 'lbl' },
|
||||
{ entity_id: 'eid', key: 'lbl', value: 'lbl' },
|
||||
{ entity_id: 'eid', key: 'metadata.annotations.ann', value: 'ann' },
|
||||
{ entity_id: 'eid', key: 'annotations.ann', value: 'ann' },
|
||||
{ entity_id: 'eid', key: 'ann', value: 'ann' },
|
||||
{ entity_id: 'eid', key: 'spec.sub.spc', value: 'spc' },
|
||||
{ entity_id: 'eid', key: 'sub.spc', value: 'spc' },
|
||||
]),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,15 +17,6 @@
|
||||
import { Entity, ENTITY_DEFAULT_NAMESPACE } from '@backstage/catalog-model';
|
||||
import type { DbEntitiesSearchRow } from './types';
|
||||
|
||||
// Search entries that start with these prefixes, also get a shorthand without
|
||||
// that prefix
|
||||
const SHORTHAND_KEY_PREFIXES = [
|
||||
'metadata.',
|
||||
'metadata.labels.',
|
||||
'metadata.annotations.',
|
||||
'spec.',
|
||||
];
|
||||
|
||||
// These are excluded in the generic loop, either because they do not make sense
|
||||
// to index, or because they are special-case always inserted whether they are
|
||||
// null or not
|
||||
@@ -159,14 +150,5 @@ export function buildEntitySearch(
|
||||
// Visit the entire structure recursively
|
||||
visitEntityPart(entityId, '', entity, result);
|
||||
|
||||
// Generate shorthands for fields directly under some common collections
|
||||
for (const row of result.slice()) {
|
||||
for (const stripPrefix of SHORTHAND_KEY_PREFIXES) {
|
||||
if (row.key.startsWith(stripPrefix)) {
|
||||
result.push({ ...row, key: row.key.substr(stripPrefix.length) });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user