Skip to content

Commit

Permalink
Native Entities refactoring (Postgres)
Browse files Browse the repository at this point in the history
Refactoring of the Postgres and EMP (entity metadata provider) interface
to make it more performant, moving beyond the original key-value store
approach for entities and allowing for "native" columns that can have
solid indexes on the columns.

The goal of this integration is to be able to create indexes on the
date fields for open source contributions. Previously, storing this
data inside of Postgres JSON columns made casting difficult or slow
to compute when querying for these values.

Also begins to ship queries away from a central cross-EMP query enum
into compartmenatlized entities.
  • Loading branch information
jeffwilcox committed May 4, 2020
1 parent c8b30f3 commit 2be09e1
Show file tree
Hide file tree
Showing 56 changed files with 873 additions and 744 deletions.
2 changes: 1 addition & 1 deletion business/operations.ts
Expand Up @@ -316,7 +316,7 @@ export class Operations {
return Array.from(this._applicationIds.values());
}

get organizationNames(): string[] {
get organizationNames(): string[] {
if (!this._organizationNames) {
const names = [];
const processed = new Set<string>();
Expand Down
2 changes: 1 addition & 1 deletion business/team.ts
Expand Up @@ -11,7 +11,7 @@ import _ from 'lodash';

import { Organization, OrganizationMembershipState } from './organization';
import { Operations } from './operations';
import { ICacheOptions, ICallback, IGetOwnerToken, ICacheOptionsPageLimiter, IPagedCacheOptions, IGetAuthorizationHeader, IPurposefulGetAuthorizationHeader, IPagedCrossOrganizationCacheOptions } from '../transitional';
import { ICacheOptions, ICacheOptionsPageLimiter, IPagedCacheOptions, IGetAuthorizationHeader, IPurposefulGetAuthorizationHeader, IPagedCrossOrganizationCacheOptions } from '../transitional';
import { TeamMember } from './teamMember';
import { TeamRepositoryPermission } from './teamRepositoryPermission';
import { IApprovalProvider } from '../entities/teamJoinApproval/approvalProvider';
Expand Down
21 changes: 10 additions & 11 deletions entities/auditLogRecord/auditLogRecord.ts
Expand Up @@ -3,18 +3,17 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

'use strict';

import { EntityField} from '../../lib/entityMetadataProvider/entityMetadataProvider';
import { IEntityMetadata, EntityMetadataType } from '../../lib/entityMetadataProvider/entityMetadata';
import { IEntityMetadataFixedQuery, FixedQueryType } from '../../lib/entityMetadataProvider/query';
import { EntityMetadataMappings, MetadataMappingDefinition } from '../../lib/entityMetadataProvider/declarations';
import { Type } from './type';
import { PostgresGetAllEntities, PostgresJsonEntityQuery, PostgresGetByID } from '../../lib/entityMetadataProvider/postgres';
import { PostgresGetAllEntities, PostgresJsonEntityQuery, PostgresGetByID, PostgresSettings, PostgresConfiguration } from '../../lib/entityMetadataProvider/postgres';
import { IDictionary } from '../../transitional';
import { v4 } from 'uuid';
import { AuditLogSource } from '.';
import { stringOrNumberAsString } from '../../utils';
import { MemorySettings } from '../../lib/entityMetadataProvider/memory';

const type = Type;

Expand Down Expand Up @@ -142,7 +141,7 @@ export class AuditLogRecordQueryRecordsByTeamId implements IEntityMetadataFixedQ
EntityMetadataMappings.Register(type, MetadataMappingDefinition.EntityInstantiate, () => { return new AuditLogRecord(); });
EntityMetadataMappings.Register(type, MetadataMappingDefinition.EntityIdColumnName, recordId);

EntityMetadataMappings.Register(type, MetadataMappingDefinition.MemoryMapping, new Map<string, string>([
EntityMetadataMappings.Register(type, MemorySettings.MemoryMapping, new Map<string, string>([
[Field.recordSource, (Field.recordSource).toLowerCase()],
[Field.action, (Field.action).toLowerCase()],
[Field.actorId, (Field.actorId).toLowerCase()],
Expand All @@ -165,11 +164,11 @@ EntityMetadataMappings.Register(type, MetadataMappingDefinition.MemoryMapping, n
[Field.userCorporateId, (Field.userCorporateId).toLowerCase()],
[Field.userCorporateUsername, (Field.userCorporateUsername).toLowerCase()],
]));
EntityMetadataMappings.RuntimeValidateMappings(type, MetadataMappingDefinition.MemoryMapping, fieldNames, [recordId]);
EntityMetadataMappings.RuntimeValidateMappings(type, MemorySettings.MemoryMapping, fieldNames, [recordId]);

EntityMetadataMappings.Register(type, MetadataMappingDefinition.PostgresDefaultTableName, 'auditlog');
EntityMetadataMappings.Register(type, MetadataMappingDefinition.PostgresDefaultTypeColumnName, 'auditlogrecord');
EntityMetadataMappings.Register(type, MetadataMappingDefinition.PostgresMapping, new Map<string, string>([
PostgresConfiguration.SetDefaultTableName(type, 'auditlog');
EntityMetadataMappings.Register(type, PostgresSettings.PostgresDefaultTypeColumnName, 'auditlogrecord');
PostgresConfiguration.MapFieldsToColumnNames(type, new Map<string, string>([
[Field.recordSource, (Field.recordSource).toLowerCase()],
[Field.action, (Field.action).toLowerCase()],
[Field.actorId, (Field.actorId).toLowerCase()],
Expand All @@ -192,9 +191,9 @@ EntityMetadataMappings.Register(type, MetadataMappingDefinition.PostgresMapping,
[Field.userCorporateId, (Field.userCorporateId).toLowerCase()],
[Field.userCorporateUsername, (Field.userCorporateUsername).toLowerCase()],
]));
EntityMetadataMappings.RuntimeValidateMappings(type, MetadataMappingDefinition.PostgresMapping, fieldNames, [recordId]);
PostgresConfiguration.ValidateMappings(type, fieldNames, [recordId]);

EntityMetadataMappings.Register(type, MetadataMappingDefinition.PostgresQueries, (query: IEntityMetadataFixedQuery, mapMetadataPropertiesToFields: string[], metadataColumnName: string, tableName: string, getEntityTypeColumnValue) => {
EntityMetadataMappings.Register(type, PostgresSettings.PostgresQueries, (query: IEntityMetadataFixedQuery, mapMetadataPropertiesToFields: string[], metadataColumnName: string, tableName: string, getEntityTypeColumnValue) => {
const entityTypeColumn = mapMetadataPropertiesToFields[EntityField.Type];
const entityTypeValue = getEntityTypeColumnValue(type);
switch (query.fixedQueryType) {
Expand Down Expand Up @@ -251,7 +250,7 @@ EntityMetadataMappings.Register(type, MetadataMappingDefinition.PostgresQueries,
}
});

EntityMetadataMappings.Register(type, MetadataMappingDefinition.MemoryQueries, (query: IEntityMetadataFixedQuery, allInTypeBin: IEntityMetadata[]) => {
EntityMetadataMappings.Register(type, MemorySettings.MemoryQueries, (query: IEntityMetadataFixedQuery, allInTypeBin: IEntityMetadata[]) => {
switch (query.fixedQueryType) {
default:
throw new Error(`The fixed query type "${query.fixedQueryType}" is not implemented by this provider for the type ${type}, or is of an unknown type`);
Expand Down
2 changes: 0 additions & 2 deletions entities/auditLogRecord/auditLogRecordProvider.ts
Expand Up @@ -3,8 +3,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

'use strict';

import { IEntityMetadata, EntityMetadataBase, IEntityMetadataBaseOptions } from '../../lib/entityMetadataProvider/entityMetadata';
import { AuditLogRecord, AuditLogRecordQueryUndoCandidatesByThirdPartyId, AuditLogRecordQueryRecordsByActorThirdPartyId, AuditLogRecordQueryRecordsByUserThirdPartyId, AuditLogRecordQueryRecordsByRepositoryId, AuditLogRecordQueryRecordsByTeamId } from './auditLogRecord';
import { EntityImplementation } from './auditLogRecord';
Expand Down

0 comments on commit 2be09e1

Please sign in to comment.