removed source and target schema. Not useful

This commit is contained in:
2024-10-08 22:52:14 +03:00
parent 800e2746e0
commit 19e8d648fc
12 changed files with 28 additions and 58 deletions
+4 -2
View File
@@ -13,14 +13,16 @@
} }
let backlinks = graph.parentEdges.map(edge => { let backlinks = graph.parentEdges.map(edge => {
let schema = channel.schemas.find((s) => s.name === edge.sourceSchema); const parentRecord = graph.records.find( record => record.id === edge.source);
let schema = channel.schemas.find((s) => s.name === parentRecord.schema);
let edgeField = findEdgeField(schema,edge.field); let edgeField = findEdgeField(schema,edge.field);
if(!edgeField){ if(!edgeField){
return null; return null;
} }
return { return {
field: edgeField.label, field: edgeField.label,
record: graph.records.find( record => record.id === edge.source) record: parentRecord
} }
}).filter( edgeOrNull => !!edgeOrNull) }).filter( edgeOrNull => !!edgeOrNull)
</script> </script>
@@ -6,8 +6,6 @@ export function insertEdges(graph, sourceRecord, targetRecords, fieldName, actio
return { return {
target: r.id, target: r.id,
source: sourceRecord.id, source: sourceRecord.id,
sourceSchema: sourceRecord.schema,
targetSchema: r.schema,
field: fieldName, field: fieldName,
depth: 1, depth: 1,
rank: "" rank: ""
-3
View File
@@ -79,11 +79,8 @@ class SetupDatabase extends Command
Database::make()->getSchemaBuilder()->create('edges', function (Blueprint $table) { Database::make()->getSchemaBuilder()->create('edges', function (Blueprint $table) {
$table->uuid('source'); $table->uuid('source');
$table->uuid('target'); $table->uuid('target');
$table->string('sourceSchema');
$table->string('targetSchema');
$table->string('field'); $table->string('field');
$table->string('rank'); $table->string('rank');
$table->unique(['source', 'target', "field"]); $table->unique(['source', 'target', "field"]);
}); });
} }
+1 -5
View File
@@ -14,8 +14,6 @@ final class Edge
public string $source, public string $source,
public string $target, public string $target,
public string $sourceSchema,
public string $targetSchema,
public string $field, public string $field,
public string $rank = "a", public string $rank = "a",
public int $depth = 0, public int $depth = 0,
@@ -29,7 +27,7 @@ final class Edge
public function equal(Edge $edge): bool public function equal(Edge $edge): bool
{ {
return $this->targetSchema === $edge->targetSchema && $this->field === $edge->field && $this->target === $edge->target && $this->source === $edge->source; return $this->field === $edge->field && $this->target === $edge->target && $this->source === $edge->source;
} }
public function toArray(): array public function toArray(): array
@@ -51,8 +49,6 @@ final class Edge
source: data_get($data, 'source'), source: data_get($data, 'source'),
target: data_get($data, 'target'), target: data_get($data, 'target'),
sourceSchema: data_get($data, 'sourceSchema'),
targetSchema: data_get($data, 'targetSchema'),
field: data_get($data, 'field'), field: data_get($data, 'field'),
rank: data_get($data, 'rank'), rank: data_get($data, 'rank'),
depth: data_get($data, 'depth', 0), depth: data_get($data, 'depth', 0),
-4
View File
@@ -78,8 +78,6 @@ class EdgeRepo
return new Edge( return new Edge(
source: $edge->source, source: $edge->source,
target: $edge->target, target: $edge->target,
sourceSchema: $edge->sourceSchema,
targetSchema: $edge->targetSchema,
field: $edge->field, field: $edge->field,
rank: $edge->rank, rank: $edge->rank,
depth: $edge->depth ?? 0 depth: $edge->depth ?? 0
@@ -92,8 +90,6 @@ class EdgeRepo
Database::make()->table("edges") Database::make()->table("edges")
->where("source", $edge->source) ->where("source", $edge->source)
->where("target", $edge->target) ->where("target", $edge->target)
->where("sourceSchema", $edge->sourceSchema)
->where("targetSchema", $edge->targetSchema)
->where("field", $edge->field) ->where("field", $edge->field)
->delete(); ->delete();
} }
-13
View File
@@ -14,8 +14,6 @@ class EdgeService
public function create( public function create(
string $source, string $source,
string $target, string $target,
string $sourceSchema,
string $targetSchema,
string $field, string $field,
string $rank, string $rank,
): Edge ): Edge
@@ -23,11 +21,8 @@ class EdgeService
$edge = new Edge( $edge = new Edge(
source: $source, source: $source,
target: $target, target: $target,
sourceSchema: $sourceSchema,
targetSchema: $targetSchema,
field: $field, field: $field,
rank: $rank, rank: $rank,
); );
@@ -37,14 +32,12 @@ class EdgeService
/** /**
* @param string $source * @param string $source
* @param string $sourceSchema
* @param list<EdgeInputData> $edges * @param list<EdgeInputData> $edges
* @return list<Edge> * @return list<Edge>
* @throws LucentException * @throws LucentException
*/ */
public function createManyForRecord( public function createManyForRecord(
string $source, string $source,
string $sourceSchema,
array $edges, array $edges,
): array ): array
{ {
@@ -55,8 +48,6 @@ class EdgeService
$edgeCollection[] = new Edge( $edgeCollection[] = new Edge(
source: $source, source: $source,
target: $edge->target, target: $edge->target,
sourceSchema: $sourceSchema,
targetSchema: $edge->targetSchema,
field: $edge->field, field: $edge->field,
rank: $lastRank->get(), rank: $lastRank->get(),
); );
@@ -68,13 +59,11 @@ class EdgeService
/** /**
* @param string $source * @param string $source
* @param string $sourceSchema
* @param list<EdgeInputData> $edges * @param list<EdgeInputData> $edges
* @return list<Edge> * @return list<Edge>
*/ */
public function replaceManyForRecord( public function replaceManyForRecord(
string $source, string $source,
string $sourceSchema,
array $edges, array $edges,
): array ): array
{ {
@@ -85,8 +74,6 @@ class EdgeService
$edgeCollection[] = new Edge( $edgeCollection[] = new Edge(
source: $source, source: $source,
target: $edge->target, target: $edge->target,
sourceSchema: $sourceSchema,
targetSchema: $edge->targetSchema,
field: $edge->field, field: $edge->field,
rank: $lastRank->get(), rank: $lastRank->get(),
); );
+4 -5
View File
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Lucent\Edge\EdgeService; use Lucent\Edge\EdgeService;
use Lucent\Query\Query; use Lucent\Query\Query;
use Lucent\Record\InputData\EdgeInputData;
class EdgeController extends Controller class EdgeController extends Controller
{ {
@@ -19,13 +20,11 @@ class EdgeController extends Controller
public function insertMany(Request $request) public function insertMany(Request $request)
{ {
$this->edgeService->createMany( $this->edgeService->createManyForRecord(
source: $request->input("source"), source: $request->input("source"),
sourceSchema: $request->input("sourceSchema"), edges: array_map(fn(string $target)=> new EdgeInputData($target,$request->input("field")),$request->input("targets"))
targetSchema: $request->input("targetSchema"),
field: $request->input("field"),
targets: $request->input("targets"),
); );
$graph = $this->query $graph = $this->query
->filter(["id" => $request->input("source")]) ->filter(["id" => $request->input("source")])
->limit(1) ->limit(1)
@@ -15,7 +15,7 @@ class PgsqlDatabaseGraph implements DatabaseGraph
public function getChildren(array $ids, QueryOptions $options): array public function getChildren(array $ids, QueryOptions $options): array
{ {
$subquery = Database::make()->table('edges AS g') $subquery = Database::make()->table('edges AS g')
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth ')) ->select(DB::raw('g.source,g.target,g.rank,g.field, 1 as depth '))
->whereIn('source', $ids); ->whereIn('source', $ids);
if (!empty($options->childrenFields)) { if (!empty($options->childrenFields)) {
@@ -25,7 +25,7 @@ class PgsqlDatabaseGraph implements DatabaseGraph
$subquery->limit($options->childrenLimit) $subquery->limit($options->childrenLimit)
->unionAll( ->unionAll(
Database::make()->table(DB::raw("edges AS g, search_graph AS sg ")) Database::make()->table(DB::raw("edges AS g, search_graph AS sg "))
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth') ->selectRaw('g.source,g.target,g.rank,g.field,sg.depth + 1 as depth')
->whereRaw("g.source = sg.target") ->whereRaw("g.source = sg.target")
->where("depth", "<", $options->childrenDepth) ->where("depth", "<", $options->childrenDepth)
->orderBy("rank") ->orderBy("rank")
@@ -43,19 +43,18 @@ class PgsqlDatabaseGraph implements DatabaseGraph
public function getParents(array $ids, QueryOptions $options): array public function getParents(array $ids, QueryOptions $options): array
{ {
$subquery = Database::make()->table('edges AS g') $subquery = Database::make()->table('edges AS g')
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth ')) ->select(DB::raw('g.source,g.target,g.rank,g.field, 1 as depth '))
->limit($options->parentsLimit) ->limit($options->parentsLimit)
->whereIn('g.target', $ids) ->whereIn('g.target', $ids)
->unionAll( ->unionAll(
Database::make()->table(DB::raw("edges AS g, search_graph AS sg ")) Database::make()->table(DB::raw("edges AS g, search_graph AS sg "))
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth') ->selectRaw('g.source,g.target,g.rank,g.field,sg.depth + 1 as depth')
->whereRaw("g.target = sg.source") ->whereRaw("g.target = sg.source")
->where("depth", "<", $options->parentsDepth) ->where("depth", "<", $options->parentsDepth)
->orderBy("rank") ->orderBy("rank")
); );
return Database::make()->table('search_graph') return Database::make()->table('search_graph')
// ->select(DB::raw('sg.source,sg.target,sg.rank,sg."sourceSchema",sg."targetSchema",sg.field,sg.depth'))
->withRecursiveExpression('search_graph', $subquery) ->withRecursiveExpression('search_graph', $subquery)
->get()->toArray(); ->get()->toArray();
} }
@@ -14,7 +14,7 @@ class SqliteDatabaseGraph implements DatabaseGraph
public function getChildren(array $ids, QueryOptions $options): array public function getChildren(array $ids, QueryOptions $options): array
{ {
$subquery = Database::make()->table('edges AS g') $subquery = Database::make()->table('edges AS g')
->select(DB::raw('g.source,g.target,g.rank,g.sourceSchema,g.targetSchema,g.field, 1 as depth ')) ->select(DB::raw('g.source,g.target,g.rank,g.field, 1 as depth '))
->whereIn('source', $ids); ->whereIn('source', $ids);
if (!empty($options->childrenFields)) { if (!empty($options->childrenFields)) {
@@ -24,14 +24,13 @@ class SqliteDatabaseGraph implements DatabaseGraph
$subquery->limit($options->childrenLimit) $subquery->limit($options->childrenLimit)
->unionAll( ->unionAll(
Database::make()->table(DB::raw("edges AS g, search_graph AS sg ")) Database::make()->table(DB::raw("edges AS g, search_graph AS sg "))
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth') ->selectRaw('g.source,g.target,g.rank,g.field,sg.depth + 1 as depth')
->whereRaw("g.source = sg.target") ->whereRaw("g.source = sg.target")
->where("depth", "<", $options->childrenDepth) ->where("depth", "<", $options->childrenDepth)
->orderBy("rank") ->orderBy("rank")
); );
return Database::make()->table('search_graph') return Database::make()->table('search_graph')
// ->select(DB::raw("*, 1 as depth "))
->withRecursiveExpression('search_graph', $subquery) ->withRecursiveExpression('search_graph', $subquery)
->get()->toArray(); ->get()->toArray();
} }
@@ -42,19 +41,18 @@ class SqliteDatabaseGraph implements DatabaseGraph
public function getParents(array $ids, QueryOptions $options): array public function getParents(array $ids, QueryOptions $options): array
{ {
$subquery = Database::make()->table('edges AS g') $subquery = Database::make()->table('edges AS g')
->select(DB::raw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field, 1 as depth ')) ->select(DB::raw('g.source,g.target,g.rank,g.field, 1 as depth '))
->limit($options->parentsLimit) ->limit($options->parentsLimit)
->whereIn('g.target', $ids) ->whereIn('g.target', $ids)
->unionAll( ->unionAll(
Database::make()->table(DB::raw("edges AS g, search_graph AS sg ")) Database::make()->table(DB::raw("edges AS g, search_graph AS sg "))
->selectRaw('g.source,g.target,g.rank,"g"."sourceSchema","g"."targetSchema",g.field,sg.depth + 1 as depth') ->selectRaw('g.source,g.target,g.rank,g.field,sg.depth + 1 as depth')
->whereRaw("g.target = sg.source") ->whereRaw("g.target = sg.source")
->where("depth", "<", $options->parentsDepth) ->where("depth", "<", $options->parentsDepth)
->orderBy("rank") ->orderBy("rank")
); );
return Database::make()->table('search_graph') return Database::make()->table('search_graph')
// ->select(DB::raw('sg.source,sg.target,sg.rank,sg."sourceSchema",sg."targetSchema",sg.field,sg.depth'))
->withRecursiveExpression('search_graph', $subquery) ->withRecursiveExpression('search_graph', $subquery)
->get()->toArray(); ->get()->toArray();
} }
+1 -1
View File
@@ -52,7 +52,7 @@ final class Graph
} }
$recordEdges = $this->edges $recordEdges = $this->edges
->filter(fn(Edge $ed) => $ed->source === $record->id) ->filter(fn(Edge $ed) => $ed->source === $record->id)
->unique(fn(Edge $ed) => $ed->targetSchema . $ed->field . $ed->target . $ed->source) ->unique(fn(Edge $ed) => $ed->field . $ed->target . $ed->source)
->sort(fn($a, $b) => $a->rank <=> $b->rank)->values(); ->sort(fn($a, $b) => $a->rank <=> $b->rank)->values();
$groupRecordEdges = []; $groupRecordEdges = [];
foreach ($recordEdges as $element) { foreach ($recordEdges as $element) {
+1 -2
View File
@@ -7,7 +7,6 @@ class EdgeInputData
{ {
public function __construct( public function __construct(
public string $target, public string $target,
public string $targetSchema,
public string $field, public string $field,
) )
{ {
@@ -15,6 +14,6 @@ class EdgeInputData
public static function fromArray(array $data): self public static function fromArray(array $data): self
{ {
return new self($data['target'], $data['targetSchema'], $data['field']); return new self($data['target'], $data['field']);
} }
} }
+2 -3
View File
@@ -127,7 +127,7 @@ readonly class RecordService
} }
RecordRepo::create($record); RecordRepo::create($record);
$newEdges = $this->edgeService->createManyForRecord($record->id, $record->schema, $edges); $newEdges = $this->edgeService->createManyForRecord($record->id, $edges);
$this->revisionService->create($record, $newEdges); $this->revisionService->create($record, $newEdges);
return $record->id; return $record->id;
@@ -246,7 +246,6 @@ readonly class RecordService
->values() ->values()
->map(fn(Edge $edge) => new EdgeInputData( ->map(fn(Edge $edge) => new EdgeInputData(
target: $edge->target, target: $edge->target,
targetSchema: $edge->targetSchema,
field: $edge->field, field: $edge->field,
))->toArray(); ))->toArray();
@@ -297,7 +296,7 @@ readonly class RecordService
id: $revision->recordId, id: $revision->recordId,
data: $revision->data->toArray(), data: $revision->data->toArray(),
status: Status::DRAFT, status: Status::DRAFT,
edges: array_map(fn(Edge $edge) => new EdgeInputData($edge->target, $edge->targetSchema, $edge->field), $revision->_edges), edges: array_map(fn(Edge $edge) => new EdgeInputData($edge->target, $edge->field), $revision->_edges),
); );
} }