mirror of
https://code.sup39.dev/repos/Wqawg
synced 2024-12-29 00:34:54 +09:00
Refactor undirected edge SQL to remove repeated filter
This commit is contained in:
parent
9cfaabc035
commit
521871c476
1 changed files with 30 additions and 18 deletions
|
@ -169,6 +169,9 @@ infixr 5 ?++
|
|||
uedge :: DBName
|
||||
uedge = DBName "temp_undirected_edge_cte"
|
||||
|
||||
ubase :: DBName
|
||||
ubase = DBName "temp_undirected_base_cte"
|
||||
|
||||
temp :: DBName
|
||||
temp = DBName "temp_hierarchy_cte"
|
||||
|
||||
|
@ -188,21 +191,30 @@ sqlUEdge
|
|||
:: (DBName -> Text) -> Text -> EntityDef -> FieldDef -> FieldDef -> Text
|
||||
sqlUEdge dbname filt tEdge bwd fwd =
|
||||
let t ^* f = dbname t <> "." <> dbname f
|
||||
in mconcat
|
||||
[ dbname uedge
|
||||
, " ("
|
||||
, dbname $ fieldDB bwd, ", ", dbname $ fieldDB fwd
|
||||
, ") AS (SELECT "
|
||||
, entityDB tEdge ^* fieldDB bwd
|
||||
, ", "
|
||||
, entityDB tEdge ^* fieldDB fwd
|
||||
, " FROM ", dbname $ entityDB tEdge
|
||||
, filt
|
||||
, " UNION ALL SELECT "
|
||||
, entityDB tEdge ^* fieldDB fwd
|
||||
, ", "
|
||||
, entityDB tEdge ^* fieldDB bwd
|
||||
, " FROM ", dbname $ entityDB tEdge
|
||||
, filt
|
||||
, ")"
|
||||
]
|
||||
sqlBase = mconcat
|
||||
[ dbname ubase
|
||||
, " ("
|
||||
, dbname $ fieldDB bwd, ", ", dbname $ fieldDB fwd
|
||||
, ") AS (SELECT "
|
||||
, entityDB tEdge ^* fieldDB bwd
|
||||
, ", "
|
||||
, entityDB tEdge ^* fieldDB fwd
|
||||
, " FROM ", dbname $ entityDB tEdge
|
||||
, filt
|
||||
, "), "
|
||||
]
|
||||
sqlEdge base = mconcat
|
||||
[ dbname uedge
|
||||
, " ("
|
||||
, dbname $ fieldDB bwd, ", ", dbname $ fieldDB fwd
|
||||
, ") AS (SELECT "
|
||||
, base ^* fieldDB bwd, ", ", base ^* fieldDB fwd
|
||||
, " FROM ", dbname base
|
||||
, " UNION ALL SELECT "
|
||||
, base ^* fieldDB fwd, ", ", base ^* fieldDB bwd
|
||||
, " FROM ", dbname base
|
||||
, ")"
|
||||
]
|
||||
in if T.null filt
|
||||
then sqlEdge $ entityDB tEdge
|
||||
else sqlBase <> sqlEdge ubase
|
||||
|
|
Loading…
Reference in a new issue