swh_graph/views/spy/
persons.rs1use super::*;
9use properties::{OptPersons, PropertiesBackend, PropertiesResult};
10
11impl<
12 G: SwhGraphWithProperties<Persons: OptPersons>,
13 MAPS: properties::MaybeMaps,
14 TIMESTAMPS: properties::MaybeTimestamps,
15 CONTENTS: properties::MaybeContents,
16 STRINGS: properties::MaybeStrings,
17 LABELNAMES: properties::MaybeLabelNames,
18 > GraphSpy<G, MAPS, TIMESTAMPS, properties::NoPersons, CONTENTS, STRINGS, LABELNAMES>
19{
20 pub fn with_persons(
21 self,
22 ) -> GraphSpy<G, MAPS, TIMESTAMPS, PersonsSpy<G>, CONTENTS, STRINGS, LABELNAMES> {
23 let GraphSpy {
24 properties:
25 properties::SwhGraphProperties {
26 path,
27 num_nodes,
28 maps,
29 timestamps,
30 persons: properties::NoPersons,
31 contents,
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: PersonsSpy {
47 graph: Arc::clone(&inner),
48 history: Arc::clone(&history),
49 },
50 contents,
51 strings,
52 label_names,
53 label_names_are_in_base64_order,
54 },
55 inner,
56 history,
57 }
58 }
59}
60
61pub struct PersonsSpy<G: SwhGraphWithProperties<Persons: OptPersons>> {
62 graph: Arc<GraphSpyInner<G>>,
63 history: Arc<Mutex<Vec<GraphAccessRecord>>>,
64}
65
66impl<G: SwhGraphWithProperties<Persons: OptPersons>> PropertiesBackend for PersonsSpy<G> {
67 type DataFilesAvailability =
68 <<G as SwhGraphWithProperties>::Persons as PropertiesBackend>::DataFilesAvailability;
69}
70
71impl<G: SwhGraphWithProperties<Persons: OptPersons>> OptPersons for PersonsSpy<G> {
72 fn author_id(&self, node: NodeId) -> PropertiesResult<'_, Option<u32>, Self> {
73 self.history
74 .lock()
75 .unwrap()
76 .push(GraphAccessRecord::Property(PropertyAccess::AuthorId(node)));
77 self.graph.graph.properties().persons.author_id(node)
78 }
79
80 fn committer_id(&self, node: NodeId) -> PropertiesResult<'_, Option<u32>, Self> {
81 self.history
82 .lock()
83 .unwrap()
84 .push(GraphAccessRecord::Property(PropertyAccess::CommitterId(
85 node,
86 )));
87 self.graph.graph.properties().persons.committer_id(node)
88 }
89 fn num_persons(&self) -> PropertiesResult<'_, usize, Self> {
90 self.graph.graph.properties().persons.num_persons()
91 }
92}