MCPcopy Index your code
hub / github.com/emwalker/digraph / intersection

Method intersection

backend/src/redis/mod.rs:112–169  ·  view source on GitHub ↗

For each topic read path (a commit, oid, repo_id combo), fetch the downset for the repo topic, save the oids in the downset to redis and perform the intersection of the sets, returning the resulting list of oids.

(
        &self,
        fetch: &F,
        topic_paths: &[TopicPath],
    )

Source from the content-addressed store, hash-verified

110 // topic, save the oids in the downset to redis and perform the intersection of the sets,
111 // returning the resulting list of oids.
112 pub fn intersection<F>(
113 &self,
114 fetch: &F,
115 topic_paths: &[TopicPath],
116 ) -> Result<HashSet<ExternalId>>
117 where
118 F: Downset,
119 {
120 if topic_paths.is_empty() {
121 log::warn!("no paths provided for transitive closure, exiting early");
122 return Ok(HashSet::new());
123 }
124
125 log::info!("redis: fetching intersection of paths {:?}", topic_paths);
126 let (head, tail) = topic_paths.split_at(1);
127 let mut con = self.connection()?;
128 let mut keys = vec![];
129
130 match head.first() {
131 Some(path) => {
132 let key = Key::downset(path);
133 keys.push(key.clone());
134
135 if !con.exists(&key)? {
136 log::info!("redis: {:?} not found in redis, saving", key);
137 let set = fetch.downset(path);
138 self.save_downset(&mut con, &key, &set)?;
139
140 if set.is_empty() {
141 return Ok(HashSet::new());
142 }
143 }
144
145 for other_path in tail {
146 let key = Key::downset(other_path);
147 keys.push(key.clone());
148
149 if !con.exists(&key)? {
150 log::info!("redis: {:?} not found in redis, saving", key);
151 let set = fetch.downset(other_path);
152 self.save_downset(&mut con, &key, &set)?;
153
154 if set.is_empty() {
155 return Ok(HashSet::new());
156 }
157 }
158 }
159
160 let set: HashSet<String> = con.sinter(&keys)?;
161 Ok(set
162 .iter()
163 .map(ExternalId::try_from)
164 .collect::<Result<HashSet<ExternalId>>>()?)
165 }
166
167 None => Ok(HashSet::new()),
168 }
169 }

Callers

nothing calls this directly

Calls 6

connectionMethod · 0.80
existsMethod · 0.80
save_downsetMethod · 0.80
is_emptyMethod · 0.45
downsetMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected