mirror of
https://github.com/Dasemu/Synapse.git
synced 2026-11-26 07:16:17 +00:00
- synapse-ffi: graph_data() returns the whole page-level graph (links, tags, property refs, block refs/embeds per page, unlinked mentions, decayed synapses) as parallel arrays with degree, backlinks, Louvain clusters and primary tags; cached by op seq, synapse state and hour. - synapse-ffi: ForceLayout, a Barnes-Hut force layout stepped from Dart on a Rust worker thread (pin/unpin for dragging, reheat). - app: Graph view with a mode selector (Network, Local, Synapses, Clusters, Namespaces, Timeline), filters (title, tag, date range, min links, orphans, journals, mentions), pan/zoom, node drag, hover highlighting, activation pulse, cluster hulls, radial namespace/tag tree, and a local graph panel on every page. Edges render as one vertex mesh, nodes in colour/size batches, culled to the viewport. - Tests: Rust extraction/mentions/cache/clusters/layout; widget tests for mode switching, filters and layout restarts; a real-app integration smoke test with frame timings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
61 lines
1.7 KiB
Dart
61 lines
1.7 KiB
Dart
import 'dart:async';
|
|
import 'dart:collection';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
/// Runs graph writes one at a time, in submission order. FFI calls are async and run on a
|
|
/// Rust thread pool, so without this two quick edits could reach the core out of order.
|
|
class WriteQueue {
|
|
WriteQueue({this.onError});
|
|
|
|
/// Called with any error a task throws; the task's own future also completes with it.
|
|
void Function(Object error, StackTrace stack)? onError;
|
|
|
|
/// Bumped after each successful write (reads pass `report: false` and do not count).
|
|
final revision = ValueNotifier<int>(0);
|
|
|
|
final _tasks = Queue<Future<void> Function()>();
|
|
bool _running = false;
|
|
Completer<void>? _idle;
|
|
|
|
bool get isIdle => !_running && _tasks.isEmpty;
|
|
|
|
/// Completes when every queued task has run.
|
|
Future<void> get idle {
|
|
if (isIdle) return Future.value();
|
|
return (_idle ??= Completer<void>()).future;
|
|
}
|
|
|
|
/// Queues `task`. Reads pass `report: false` so their errors do not reach [onError].
|
|
Future<T> run<T>(Future<T> Function() task, {bool report = true}) {
|
|
final done = Completer<T>();
|
|
_tasks.add(() async {
|
|
try {
|
|
final out = await task();
|
|
if (report) revision.value++;
|
|
done.complete(out);
|
|
} catch (e, st) {
|
|
if (report) onError?.call(e, st);
|
|
done.completeError(e, st);
|
|
}
|
|
});
|
|
_pump();
|
|
return done.future;
|
|
}
|
|
|
|
Future<void> _pump() async {
|
|
if (_running) return;
|
|
_running = true;
|
|
while (_tasks.isNotEmpty) {
|
|
await _tasks.removeFirst()();
|
|
}
|
|
_running = false;
|
|
final idle = _idle;
|
|
_idle = null;
|
|
idle?.complete();
|
|
}
|
|
|
|
@visibleForTesting
|
|
int get pending => _tasks.length;
|
|
}
|