Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d9b4f417f6 | |||
| eae39f92d6 | |||
| 2895f06074 | |||
| c1c16bc814 | |||
| 5885552192 |
@ -1461,17 +1461,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE t1.id = '{{uuid:data.id}}' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE (\"first_name\" = 'LookupFirst' AND \"last_name\" = 'LookupLast' AND \"date_of_birth\" = '{{timestamp}}' AND \"pronouns\" = 'they/them'))"
|
||||||
"FROM agreego.\"entity\" t1",
|
|
||||||
"JOIN agreego.\"organization\" t2 ON ",
|
|
||||||
"JOIN agreego.\"user\" t3 ON ",
|
|
||||||
"JOIN agreego.\"person\" t4 ON ",
|
|
||||||
"WHERE",
|
|
||||||
" t1.id = '{{uuid:data.id}}'",
|
|
||||||
" OR (\"first_name\" = 'LookupFirst'",
|
|
||||||
" AND \"last_name\" = 'LookupLast'",
|
|
||||||
" AND \"date_of_birth\" = '{{timestamp}}'",
|
|
||||||
" AND \"pronouns\" = 'they/them'))"
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"entity\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
@ -1614,17 +1604,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE t1.id = '{{uuid:data.id}}' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id WHERE (\"first_name\" = 'LookupFirst' AND \"last_name\" = 'LookupLast' AND \"date_of_birth\" = '{{timestamp}}' AND \"pronouns\" = 'they/them'))"
|
||||||
"FROM agreego.\"entity\" t1",
|
|
||||||
"JOIN agreego.\"organization\" t2 ON ",
|
|
||||||
"JOIN agreego.\"user\" t3 ON ",
|
|
||||||
"JOIN agreego.\"person\" t4 ON ",
|
|
||||||
"WHERE",
|
|
||||||
" t1.id = '{{uuid:data.id}}'",
|
|
||||||
" OR (\"first_name\" = 'LookupFirst'",
|
|
||||||
" AND \"last_name\" = 'LookupLast'",
|
|
||||||
" AND \"date_of_birth\" = '{{timestamp}}'",
|
|
||||||
" AND \"pronouns\" = 'they/them'))"
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"entity\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
@ -2219,12 +2199,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"order\" t2 ON t2.id = t1.id WHERE t1.id = 'abc' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"order\" t2 ON t2.id = t1.id WHERE (\"id\" = 'abc'))"
|
||||||
"FROM agreego.\"entity\" t1",
|
|
||||||
"JOIN agreego.\"order\" t2 ON ",
|
|
||||||
"WHERE",
|
|
||||||
" t1.id = 'abc'",
|
|
||||||
" OR (\"id\" = 'abc'))"
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"entity\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
@ -3499,12 +3474,7 @@
|
|||||||
"success": true,
|
"success": true,
|
||||||
"sql": [
|
"sql": [
|
||||||
[
|
[
|
||||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"invoice\" t2 ON t2.id = t1.id WHERE t1.id = '{{uuid:data.id}}' UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) FROM agreego.\"entity\" t1 LEFT JOIN agreego.\"invoice\" t2 ON t2.id = t1.id WHERE (\"id\" = '{{uuid:data.id}}'))"
|
||||||
"FROM agreego.\"entity\" t1",
|
|
||||||
"JOIN agreego.\"invoice\" t2 ON ",
|
|
||||||
"WHERE",
|
|
||||||
" t1.id = '{{uuid:data.id}}'",
|
|
||||||
" OR (\"id\" = '{{uuid:data.id}}'))"
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
"INSERT INTO agreego.\"entity\" (",
|
"INSERT INTO agreego.\"entity\" (",
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
use crate::database::action::Action;
|
use crate::database::action::Action;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
@ -13,6 +14,11 @@ pub struct Page {
|
|||||||
pub sidebar: Option<Sidebar>,
|
pub sidebar: Option<Sidebar>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub actions: Option<IndexMap<String, Action>>,
|
pub actions: Option<IndexMap<String, Action>>,
|
||||||
|
/// The personal-scope filter template ("one surface, two scopes"): the
|
||||||
|
/// "mine" predicate the page merges into its filter when the app is in
|
||||||
|
/// personal scope, e.g. {"reserved_by": "$me"}. Opaque to the engine.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub personal: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||||
@ -22,4 +28,6 @@ pub struct Sidebar {
|
|||||||
pub category: Option<String>,
|
pub category: Option<String>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub priority: Option<i32>,
|
pub priority: Option<i32>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub icon: Option<String>,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -744,9 +744,19 @@ impl Merger {
|
|||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let where_clause = format!("WHERE {}", where_parts.join(" OR "));
|
// An OR across the hierarchy join is un-indexable — it forces a full scan
|
||||||
|
// of the subtype table on every child merge. UNION lets each arm use its
|
||||||
let final_sql = format!("{} {}", fetch_sql_template, where_clause);
|
// own index (pk for the id arm, the lk_ unique index for the lookup arm)
|
||||||
|
// and still dedups, so TOO_MANY_LOOKUP_ROWS semantics are preserved.
|
||||||
|
let final_sql = if where_parts.len() == 1 {
|
||||||
|
format!("{} WHERE {}", fetch_sql_template, where_parts[0])
|
||||||
|
} else {
|
||||||
|
where_parts
|
||||||
|
.iter()
|
||||||
|
.map(|p| format!("{} WHERE {}", fetch_sql_template, p))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" UNION ")
|
||||||
|
};
|
||||||
|
|
||||||
let fetched = match self.db.query(&final_sql, None) {
|
let fetched = match self.db.query(&final_sql, None) {
|
||||||
Ok(Value::Array(table)) => {
|
Ok(Value::Array(table)) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user