Optimisation - only loop over document fields when processing PERMISSIONS clauses (#1890)
This commit is contained in:
parent
1e8903b699
commit
c7e3b927ac
3 changed files with 47 additions and 44 deletions
|
@ -13,31 +13,31 @@ use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
// Currently selected NS
|
/// Currently selected NS
|
||||||
pub ns: Option<Arc<str>>,
|
pub ns: Option<Arc<str>>,
|
||||||
// Currently selected DB
|
/// Currently selected DB
|
||||||
pub db: Option<Arc<str>>,
|
pub db: Option<Arc<str>>,
|
||||||
// Connection authentication data
|
/// Connection authentication data
|
||||||
pub auth: Arc<Auth>,
|
pub auth: Arc<Auth>,
|
||||||
// Approximately how large is the current call stack?
|
/// Approximately how large is the current call stack?
|
||||||
dive: u8,
|
dive: u8,
|
||||||
// Whether live queries are allowed?
|
/// Whether live queries are allowed?
|
||||||
pub live: bool,
|
pub live: bool,
|
||||||
// Should we force tables/events to re-run?
|
/// Should we force tables/events to re-run?
|
||||||
pub force: bool,
|
pub force: bool,
|
||||||
// Should we run permissions checks?
|
/// Should we run permissions checks?
|
||||||
pub perms: bool,
|
pub perms: bool,
|
||||||
// Should we error if tables don't exist?
|
/// Should we error if tables don't exist?
|
||||||
pub strict: bool,
|
pub strict: bool,
|
||||||
// Should we process field queries?
|
/// Should we process field queries?
|
||||||
pub fields: bool,
|
pub fields: bool,
|
||||||
// Should we process event queries?
|
/// Should we process event queries?
|
||||||
pub events: bool,
|
pub events: bool,
|
||||||
// Should we process table queries?
|
/// Should we process table queries?
|
||||||
pub tables: bool,
|
pub tables: bool,
|
||||||
// Should we process index queries?
|
/// Should we process index queries?
|
||||||
pub indexes: bool,
|
pub indexes: bool,
|
||||||
// Should we process function futures?
|
/// Should we process function futures?
|
||||||
pub futures: bool,
|
pub futures: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,10 @@ impl<'a> Document<'a> {
|
||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
stm: &Statement<'_>,
|
stm: &Statement<'_>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
// Check permission clause
|
// Check if this record exists
|
||||||
if opt.perms && opt.auth.perms() && self.id.is_some() {
|
if self.id.is_some() {
|
||||||
|
// Should we run permissions checks?
|
||||||
|
if opt.perms && opt.auth.perms() {
|
||||||
// Get the table
|
// Get the table
|
||||||
let tb = self.tb(opt, txn).await?;
|
let tb = self.tb(opt, txn).await?;
|
||||||
// Get the permission clause
|
// Get the permission clause
|
||||||
|
@ -28,7 +30,7 @@ impl<'a> Document<'a> {
|
||||||
} else {
|
} else {
|
||||||
&tb.permissions.update
|
&tb.permissions.update
|
||||||
};
|
};
|
||||||
// Match the permission clause
|
// Process the table permissions
|
||||||
match perms {
|
match perms {
|
||||||
Permission::None => return Err(Error::Ignore),
|
Permission::None => return Err(Error::Ignore),
|
||||||
Permission::Full => return Ok(()),
|
Permission::Full => return Ok(()),
|
||||||
|
@ -42,6 +44,7 @@ impl<'a> Document<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Carry on
|
// Carry on
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,13 +55,13 @@ impl<'a> Document<'a> {
|
||||||
}?;
|
}?;
|
||||||
// Check if this record exists
|
// Check if this record exists
|
||||||
if self.id.is_some() {
|
if self.id.is_some() {
|
||||||
|
// Should we run permissions checks?
|
||||||
|
if opt.perms && opt.auth.perms() {
|
||||||
// Loop through all field statements
|
// Loop through all field statements
|
||||||
for fd in self.fd(opt, txn).await?.iter() {
|
for fd in self.fd(opt, txn).await?.iter() {
|
||||||
// Loop over each field in document
|
// Loop over each field in document
|
||||||
for k in out.each(&fd.name).iter() {
|
for k in out.each(&fd.name).iter() {
|
||||||
// Check for a PERMISSIONS clause
|
// Process the field permissions
|
||||||
if opt.perms && opt.auth.perms() {
|
|
||||||
// Process field permissions
|
|
||||||
match &fd.permissions.select {
|
match &fd.permissions.select {
|
||||||
Permission::Full => (),
|
Permission::Full => (),
|
||||||
Permission::None => out.del(ctx, opt, txn, k).await?,
|
Permission::None => out.del(ctx, opt, txn, k).await?,
|
||||||
|
|
Loading…
Reference in a new issue