fix: refs #7524 default limit select
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Jorge Penadés 2024-08-06 17:08:27 +02:00
parent c31e33535d
commit b3b7e9c213
2 changed files with 10 additions and 5 deletions

View File

@ -31,20 +31,19 @@ module.exports = function(Self) {
/* /*
* Intercept GET request for find * Intercept GET request for find
*/ */
this.beforeRemote('find', async function(ctx) { this.beforeRemote('find', async ctx => {
isSelect = true; isSelect = true;
const filter = ctx.args.filter || {}; const filter = ctx.args.filter || {};
// console.log(this.dataSource, Self.dataSource); undefined/null
if (filter.limit === undefined) { if (filter.limit === undefined) {
filter.limit = 1/* limit */; filter.limit = this.app.orm.selectLimit;
ctx.args.filter = filter; ctx.args.filter = filter;
} }
}); });
this.observe('loaded', async function({data}) { this.observe('loaded', async({data}) => {
if (!isSelect) return; if (!isSelect) return;
const length = Array.isArray(data) ? data.length : data ? 1 : 0; const length = Array.isArray(data) ? data.length : data ? 1 : 0;
if (length >= 1) throw new UserError('Too many records'); if (length >= this.app.orm.selectLimit) throw new UserError('Too many records');
}); });
// Register field ACL validation // Register field ACL validation

View File

@ -0,0 +1,6 @@
module.exports = async function(app) {
if (!app.orm) {
const ormConfig = await app.models.OrmConfig.findOne();
app.orm = ormConfig;
}
};