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
-3
View File
@@ -79,11 +79,8 @@ class SetupDatabase extends Command
Database::make()->getSchemaBuilder()->create('edges', function (Blueprint $table) {
$table->uuid('source');
$table->uuid('target');
$table->string('sourceSchema');
$table->string('targetSchema');
$table->string('field');
$table->string('rank');
$table->unique(['source', 'target', "field"]);
});
}
+1 -5
View File
@@ -14,8 +14,6 @@ final class Edge
public string $source,
public string $target,
public string $sourceSchema,
public string $targetSchema,
public string $field,
public string $rank = "a",
public int $depth = 0,
@@ -29,7 +27,7 @@ final class Edge
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
@@ -51,8 +49,6 @@ final class Edge
source: data_get($data, 'source'),
target: data_get($data, 'target'),
sourceSchema: data_get($data, 'sourceSchema'),
targetSchema: data_get($data, 'targetSchema'),
field: data_get($data, 'field'),
rank: data_get($data, 'rank'),
depth: data_get($data, 'depth', 0),
-4
View File
@@ -78,8 +78,6 @@ class EdgeRepo
return new Edge(
source: $edge->source,
target: $edge->target,
sourceSchema: $edge->sourceSchema,
targetSchema: $edge->targetSchema,
field: $edge->field,
rank: $edge->rank,
depth: $edge->depth ?? 0
@@ -92,8 +90,6 @@ class EdgeRepo
Database::make()->table("edges")
->where("source", $edge->source)
->where("target", $edge->target)
->where("sourceSchema", $edge->sourceSchema)
->where("targetSchema", $edge->targetSchema)
->where("field", $edge->field)
->delete();
}
-13
View File
@@ -14,8 +14,6 @@ class EdgeService
public function create(
string $source,
string $target,
string $sourceSchema,
string $targetSchema,
string $field,
string $rank,
): Edge
@@ -23,11 +21,8 @@ class EdgeService
$edge = new Edge(
source: $source,
target: $target,
sourceSchema: $sourceSchema,
targetSchema: $targetSchema,
field: $field,
rank: $rank,
);
@@ -37,14 +32,12 @@ class EdgeService
/**
* @param string $source
* @param string $sourceSchema
* @param list<EdgeInputData> $edges
* @return list<Edge>
* @throws LucentException
*/
public function createManyForRecord(
string $source,
string $sourceSchema,
array $edges,
): array
{
@@ -55,8 +48,6 @@ class EdgeService
$edgeCollection[] = new Edge(
source: $source,
target: $edge->target,
sourceSchema: $sourceSchema,
targetSchema: $edge->targetSchema,
field: $edge->field,
rank: $lastRank->get(),
);
@@ -68,13 +59,11 @@ class EdgeService
/**
* @param string $source
* @param string $sourceSchema
* @param list<EdgeInputData> $edges
* @return list<Edge>
*/
public function replaceManyForRecord(
string $source,
string $sourceSchema,
array $edges,
): array
{
@@ -85,8 +74,6 @@ class EdgeService
$edgeCollection[] = new Edge(
source: $source,
target: $edge->target,
sourceSchema: $sourceSchema,
targetSchema: $edge->targetSchema,
field: $edge->field,
rank: $lastRank->get(),
);
+4 -5
View File
@@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Lucent\Edge\EdgeService;
use Lucent\Query\Query;
use Lucent\Record\InputData\EdgeInputData;
class EdgeController extends Controller
{
@@ -19,13 +20,11 @@ class EdgeController extends Controller
public function insertMany(Request $request)
{
$this->edgeService->createMany(
$this->edgeService->createManyForRecord(
source: $request->input("source"),
sourceSchema: $request->input("sourceSchema"),
targetSchema: $request->input("targetSchema"),
field: $request->input("field"),
targets: $request->input("targets"),
edges: array_map(fn(string $target)=> new EdgeInputData($target,$request->input("field")),$request->input("targets"))
);
$graph = $this->query
->filter(["id" => $request->input("source")])
->limit(1)
@@ -15,7 +15,7 @@ class PgsqlDatabaseGraph implements DatabaseGraph
public function getChildren(array $ids, QueryOptions $options): array
{
$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);
if (!empty($options->childrenFields)) {
@@ -25,7 +25,7 @@ class PgsqlDatabaseGraph implements DatabaseGraph
$subquery->limit($options->childrenLimit)
->unionAll(
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")
->where("depth", "<", $options->childrenDepth)
->orderBy("rank")
@@ -43,19 +43,18 @@ class PgsqlDatabaseGraph implements DatabaseGraph
public function getParents(array $ids, QueryOptions $options): array
{
$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)
->whereIn('g.target', $ids)
->unionAll(
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")
->where("depth", "<", $options->parentsDepth)
->orderBy("rank")
);
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)
->get()->toArray();
}
@@ -14,7 +14,7 @@ class SqliteDatabaseGraph implements DatabaseGraph
public function getChildren(array $ids, QueryOptions $options): array
{
$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);
if (!empty($options->childrenFields)) {
@@ -24,14 +24,13 @@ class SqliteDatabaseGraph implements DatabaseGraph
$subquery->limit($options->childrenLimit)
->unionAll(
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")
->where("depth", "<", $options->childrenDepth)
->orderBy("rank")
);
return Database::make()->table('search_graph')
// ->select(DB::raw("*, 1 as depth "))
->withRecursiveExpression('search_graph', $subquery)
->get()->toArray();
}
@@ -42,19 +41,18 @@ class SqliteDatabaseGraph implements DatabaseGraph
public function getParents(array $ids, QueryOptions $options): array
{
$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)
->whereIn('g.target', $ids)
->unionAll(
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")
->where("depth", "<", $options->parentsDepth)
->orderBy("rank")
);
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)
->get()->toArray();
}
+8 -8
View File
@@ -14,11 +14,11 @@ final class Graph
* @param Collection<Edge> $edges
* */
public function __construct(
public Collection $records,
public Collection $edges,
public Collection $parentEdges,
public Collection $records,
public Collection $edges,
public Collection $parentEdges,
public QueryOptions $queryOptions,
public ?int $total = null,
public ?int $total = null,
)
{
}
@@ -47,12 +47,12 @@ final class Graph
public function findChildren(QueryRecord $record, int $depth = 1): QueryRecord
{
if($this->queryOptions->childrenDepth < $depth){
if ($this->queryOptions->childrenDepth < $depth) {
return $record;
}
$recordEdges = $this->edges
->filter(fn(Edge $ed) => $ed->source === $record->id )
->unique(fn(Edge $ed) => $ed->targetSchema . $ed->field . $ed->target . $ed->source)
->filter(fn(Edge $ed) => $ed->source === $record->id)
->unique(fn(Edge $ed) => $ed->field . $ed->target . $ed->source)
->sort(fn($a, $b) => $a->rank <=> $b->rank)->values();
$groupRecordEdges = [];
foreach ($recordEdges as $element) {
@@ -78,7 +78,7 @@ final class Graph
public function findParents(QueryRecord $record, int $depth = 1): QueryRecord
{
if($this->queryOptions->parentsDepth < $depth){
if ($this->queryOptions->parentsDepth < $depth) {
return $record;
}
$recordEdges = $this->parentEdges->filter(fn(Edge $ed) => $ed->target === $record->id)->where("depth", $depth)->values()->sort(fn($a, $b) => $a->rank <=> $b->rank)->values();
+1 -2
View File
@@ -7,7 +7,6 @@ class EdgeInputData
{
public function __construct(
public string $target,
public string $targetSchema,
public string $field,
)
{
@@ -15,6 +14,6 @@ class EdgeInputData
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);
$newEdges = $this->edgeService->createManyForRecord($record->id, $record->schema, $edges);
$newEdges = $this->edgeService->createManyForRecord($record->id, $edges);
$this->revisionService->create($record, $newEdges);
return $record->id;
@@ -246,7 +246,6 @@ readonly class RecordService
->values()
->map(fn(Edge $edge) => new EdgeInputData(
target: $edge->target,
targetSchema: $edge->targetSchema,
field: $edge->field,
))->toArray();
@@ -297,7 +296,7 @@ readonly class RecordService
id: $revision->recordId,
data: $revision->data->toArray(),
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),
);
}