added index on media entity_id, report query with unindexed fields

This commit is contained in:
dswbx
2025-02-22 22:09:50 +01:00
parent b8f87a2097
commit 9a741f49a0
4 changed files with 26 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ import {
UnableToConnectException
} from "../errors";
import { MutatorEvents, RepositoryEvents } from "../events";
import type { Field } from "../fields/Field";
import type { EntityIndex } from "../fields/indices/EntityIndex";
import type { EntityRelation } from "../relations";
import { RelationAccessor } from "../relations/RelationAccessor";
@@ -142,6 +143,16 @@ export class EntityManager<TBD extends object = DefaultDB> {
return this.indices.some((e) => e.name === name);
}
// @todo: add to Connection whether first index is used or not
getIndexedFields(_entity: Entity | string): Field[] {
const entity = this.entity(_entity);
const indices = this.getIndicesOf(entity);
const rel_fields = entity.fields.filter((f) => f.type === "relation");
// assuming only first
const idx_fields = indices.map((index) => index.fields[0]);
return [entity.getPrimaryField(), ...rel_fields, ...idx_fields].filter(Boolean) as Field[];
}
addRelation(relation: EntityRelation) {
// check if entities are registered
if (!this.entity(relation.source.entity.name) || !this.entity(relation.target.entity.name)) {