Merge branch 'feat/index-sortable-fields' of github.com:payloadcms/payload
This commit is contained in:
@@ -80,6 +80,7 @@ export default joi.object({
|
||||
}),
|
||||
local: joi.boolean(),
|
||||
upload: joi.object(),
|
||||
indexSortableFields: joi.boolean(),
|
||||
rateLimit: joi.object()
|
||||
.keys({
|
||||
window: joi.number(),
|
||||
|
||||
@@ -120,6 +120,7 @@ export type Config = {
|
||||
},
|
||||
defaultDepth?: number;
|
||||
maxDepth?: number;
|
||||
indexSortableFields?: boolean;
|
||||
rateLimit?: {
|
||||
window?: number;
|
||||
max?: number;
|
||||
@@ -143,7 +144,7 @@ export type Config = {
|
||||
hooks?: {
|
||||
afterError?: AfterErrorHook;
|
||||
};
|
||||
plugins?: Plugin[]
|
||||
plugins?: Plugin[];
|
||||
};
|
||||
|
||||
export type SanitizedConfig = Omit<DeepRequired<Config>, 'collections' | 'globals'> & {
|
||||
|
||||
@@ -9,7 +9,7 @@ const buildModel = (config: SanitizedConfig): mongoose.PaginateModel<any> | null
|
||||
const Globals = mongoose.model('globals', globalsSchema);
|
||||
|
||||
Object.values(config.globals).forEach((globalConfig) => {
|
||||
const globalSchema = buildSchema(config, globalConfig.fields, {});
|
||||
const globalSchema = buildSchema(config, globalConfig.fields, { global: true });
|
||||
Globals.discriminator(globalConfig.slug, globalSchema);
|
||||
});
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
import { Schema, SchemaDefinition, SchemaOptions } from 'mongoose';
|
||||
import { SanitizedConfig } from '../config/types';
|
||||
import { ArrayField, Block, BlockField, Field, GroupField, RadioField, RelationshipField, RowField, SelectField, UploadField } from '../fields/config/types';
|
||||
import sortableFieldTypes from '../fields/sortableFieldTypes';
|
||||
|
||||
type BuildSchemaOptions = {
|
||||
options?: SchemaOptions
|
||||
allowIDField?: boolean
|
||||
disableRequired?: boolean
|
||||
global?: boolean
|
||||
}
|
||||
|
||||
type FieldSchemaGenerator = (field: Field, fields: SchemaDefinition, config: SanitizedConfig, buildSchemaOptions: BuildSchemaOptions) => SchemaDefinition;
|
||||
@@ -89,10 +91,15 @@ const buildSchema = (config: SanitizedConfig, configFields: Field[], buildSchema
|
||||
if (fieldSchema) {
|
||||
fields = fieldSchema(field, fields, config, buildSchemaOptions);
|
||||
}
|
||||
|
||||
// geospatial field index must be created after the schema is created
|
||||
if (fieldIndexMap[field.type]) {
|
||||
indexFields.push(...fieldIndexMap[field.type](field, config));
|
||||
}
|
||||
|
||||
if (config.indexSortableFields && !buildSchemaOptions.global && !field.index && !field.hidden && sortableFieldTypes.indexOf(field.type) > -1) {
|
||||
indexFields.push({ [field.name]: 1 });
|
||||
}
|
||||
});
|
||||
|
||||
const schema = new Schema(fields, options);
|
||||
|
||||
Reference in New Issue
Block a user