swh_graph/views/spy/
contents.rs1use super::*;
9use properties::{OptContents, PropertiesBackend, PropertiesResult};
10
11impl<
12 G: SwhGraphWithProperties<Contents: OptContents>,
13 MAPS: properties::MaybeMaps,
14 TIMESTAMPS: properties::MaybeTimestamps,
15 PERSONS: properties::MaybePersons,
16 STRINGS: properties::MaybeStrings,
17 LABELNAMES: properties::MaybeLabelNames,
18 > GraphSpy<G, MAPS, TIMESTAMPS, PERSONS, properties::NoContents, STRINGS, LABELNAMES>
19{
20 pub fn with_contents(
21 self,
22 ) -> GraphSpy<G, MAPS, TIMESTAMPS, PERSONS, ContentsSpy<G>, STRINGS, LABELNAMES> {
23 let GraphSpy {
24 properties:
25 properties::SwhGraphProperties {
26 path,
27 num_nodes,
28 maps,
29 timestamps,
30 persons,
31 contents: properties::NoContents,
32 strings,
33 label_names,
34 label_names_are_in_base64_order,
35 },
36 inner,
37 history,
38 } = self;
39
40 GraphSpy {
41 properties: properties::SwhGraphProperties {
42 path,
43 num_nodes,
44 maps,
45 timestamps,
46 persons,
47 contents: ContentsSpy {
48 graph: Arc::clone(&inner),
49 history: Arc::clone(&history),
50 },
51 strings,
52 label_names,
53 label_names_are_in_base64_order,
54 },
55 inner,
56 history,
57 }
58 }
59}
60
61pub struct ContentsSpy<G: SwhGraphWithProperties<Contents: OptContents>> {
62 graph: Arc<GraphSpyInner<G>>,
63 history: Arc<Mutex<Vec<GraphAccessRecord>>>,
64}
65
66impl<G: SwhGraphWithProperties<Contents: OptContents>> PropertiesBackend for ContentsSpy<G> {
67 type DataFilesAvailability =
68 <<G as SwhGraphWithProperties>::Contents as PropertiesBackend>::DataFilesAvailability;
69}
70
71impl<G: SwhGraphWithProperties<Contents: OptContents>> OptContents for ContentsSpy<G> {
72 fn is_skipped_content(&self, node: NodeId) -> PropertiesResult<'_, Option<bool>, Self> {
73 self.history
74 .lock()
75 .unwrap()
76 .push(GraphAccessRecord::Property(
77 PropertyAccess::IsSkippedContent(node),
78 ));
79 self.graph
80 .graph
81 .properties()
82 .contents
83 .is_skipped_content(node)
84 }
85
86 fn content_length(&self, node: NodeId) -> PropertiesResult<'_, Option<u64>, Self> {
87 self.history
88 .lock()
89 .unwrap()
90 .push(GraphAccessRecord::Property(PropertyAccess::ContentLength(
91 node,
92 )));
93 self.graph.graph.properties().contents.content_length(node)
94 }
95}