diff options
Diffstat (limited to 'src/lib/client.rs')
| -rw-r--r-- | src/lib/client.rs | 132 |
1 files changed, 75 insertions, 57 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs index 16cfe30..9253022 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs | |||
| @@ -1103,16 +1103,18 @@ pub async fn get_state_from_cache( | |||
| 1103 | ) -> Result<RepoState> { | 1103 | ) -> Result<RepoState> { |
| 1104 | if let Some(git_repo_path) = git_repo_path { | 1104 | if let Some(git_repo_path) = git_repo_path { |
| 1105 | RepoState::try_from( | 1105 | RepoState::try_from( |
| 1106 | get_events_from_local_cache(git_repo_path, vec![get_filter_state_events( | 1106 | get_events_from_local_cache( |
| 1107 | &repo_ref.coordinates(), | 1107 | git_repo_path, |
| 1108 | )]) | 1108 | vec![get_filter_state_events(&repo_ref.coordinates())], |
| 1109 | ) | ||
| 1109 | .await?, | 1110 | .await?, |
| 1110 | ) | 1111 | ) |
| 1111 | } else { | 1112 | } else { |
| 1112 | RepoState::try_from( | 1113 | RepoState::try_from( |
| 1113 | get_event_from_global_cache(git_repo_path, vec![get_filter_state_events( | 1114 | get_event_from_global_cache( |
| 1114 | &repo_ref.coordinates(), | 1115 | git_repo_path, |
| 1115 | )]) | 1116 | vec![get_filter_state_events(&repo_ref.coordinates())], |
| 1117 | ) | ||
| 1116 | .await?, | 1118 | .await?, |
| 1117 | ) | 1119 | ) |
| 1118 | } | 1120 | } |
| @@ -1178,17 +1180,20 @@ async fn create_relays_request( | |||
| 1178 | } | 1180 | } |
| 1179 | 1181 | ||
| 1180 | if let Some(git_repo_path) = git_repo_path { | 1182 | if let Some(git_repo_path) = git_repo_path { |
| 1181 | for event in &get_events_from_local_cache(git_repo_path, vec![ | 1183 | for event in &get_events_from_local_cache( |
| 1182 | nostr::Filter::default() | 1184 | git_repo_path, |
| 1183 | .kinds(vec![Kind::GitPatch]) | 1185 | vec![ |
| 1184 | .custom_tags( | 1186 | nostr::Filter::default() |
| 1185 | SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), | 1187 | .kinds(vec![Kind::GitPatch]) |
| 1186 | repo_coordinates_without_relays | 1188 | .custom_tags( |
| 1187 | .iter() | 1189 | SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), |
| 1188 | .map(|c| c.coordinate.to_string()) | 1190 | repo_coordinates_without_relays |
| 1189 | .collect::<Vec<String>>(), | 1191 | .iter() |
| 1190 | ), | 1192 | .map(|c| c.coordinate.to_string()) |
| 1191 | ]) | 1193 | .collect::<Vec<String>>(), |
| 1194 | ), | ||
| 1195 | ], | ||
| 1196 | ) | ||
| 1192 | .await? | 1197 | .await? |
| 1193 | { | 1198 | { |
| 1194 | if event_is_patch_set_root(event) || event_is_revision_root(event) { | 1199 | if event_is_patch_set_root(event) || event_is_revision_root(event) { |
| @@ -1198,11 +1203,11 @@ async fn create_relays_request( | |||
| 1198 | } | 1203 | } |
| 1199 | } | 1204 | } |
| 1200 | 1205 | ||
| 1201 | let profile_events = | 1206 | let profile_events = get_event_from_global_cache( |
| 1202 | get_event_from_global_cache(git_repo_path, vec![get_filter_contributor_profiles( | 1207 | git_repo_path, |
| 1203 | contributors.clone(), | 1208 | vec![get_filter_contributor_profiles(contributors.clone())], |
| 1204 | )]) | 1209 | ) |
| 1205 | .await?; | 1210 | .await?; |
| 1206 | for c in &contributors { | 1211 | for c in &contributors { |
| 1207 | if let Some(event) = profile_events | 1212 | if let Some(event) = profile_events |
| 1208 | .iter() | 1213 | .iter() |
| @@ -1768,17 +1773,20 @@ pub async fn get_proposals_and_revisions_from_cache( | |||
| 1768 | git_repo_path: &Path, | 1773 | git_repo_path: &Path, |
| 1769 | repo_coordinates: HashSet<Nip19Coordinate>, | 1774 | repo_coordinates: HashSet<Nip19Coordinate>, |
| 1770 | ) -> Result<Vec<nostr::Event>> { | 1775 | ) -> Result<Vec<nostr::Event>> { |
| 1771 | let mut proposals = get_events_from_local_cache(git_repo_path, vec![ | 1776 | let mut proposals = get_events_from_local_cache( |
| 1772 | nostr::Filter::default() | 1777 | git_repo_path, |
| 1773 | .kind(nostr::Kind::GitPatch) | 1778 | vec![ |
| 1774 | .custom_tags( | 1779 | nostr::Filter::default() |
| 1775 | nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), | 1780 | .kind(nostr::Kind::GitPatch) |
| 1776 | repo_coordinates | 1781 | .custom_tags( |
| 1777 | .iter() | 1782 | nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), |
| 1778 | .map(|c| c.coordinate.to_string()) | 1783 | repo_coordinates |
| 1779 | .collect::<Vec<String>>(), | 1784 | .iter() |
| 1780 | ), | 1785 | .map(|c| c.coordinate.to_string()) |
| 1781 | ]) | 1786 | .collect::<Vec<String>>(), |
| 1787 | ), | ||
| 1788 | ], | ||
| 1789 | ) | ||
| 1782 | .await? | 1790 | .await? |
| 1783 | .iter() | 1791 | .iter() |
| 1784 | .filter(|e| event_is_patch_set_root(e)) | 1792 | .filter(|e| event_is_patch_set_root(e)) |
| @@ -1794,23 +1802,29 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 1794 | repo_ref: &RepoRef, | 1802 | repo_ref: &RepoRef, |
| 1795 | proposal_id: &nostr::EventId, | 1803 | proposal_id: &nostr::EventId, |
| 1796 | ) -> Result<Vec<nostr::Event>> { | 1804 | ) -> Result<Vec<nostr::Event>> { |
| 1797 | let mut commit_events = get_events_from_local_cache(git_repo_path, vec![ | 1805 | let mut commit_events = get_events_from_local_cache( |
| 1798 | nostr::Filter::default() | 1806 | git_repo_path, |
| 1799 | .kind(nostr::Kind::GitPatch) | 1807 | vec![ |
| 1800 | .event(*proposal_id), | 1808 | nostr::Filter::default() |
| 1801 | nostr::Filter::default() | 1809 | .kind(nostr::Kind::GitPatch) |
| 1802 | .kind(nostr::Kind::GitPatch) | 1810 | .event(*proposal_id), |
| 1803 | .id(*proposal_id), | 1811 | nostr::Filter::default() |
| 1804 | ]) | 1812 | .kind(nostr::Kind::GitPatch) |
| 1813 | .id(*proposal_id), | ||
| 1814 | ], | ||
| 1815 | ) | ||
| 1805 | .await?; | 1816 | .await?; |
| 1806 | 1817 | ||
| 1807 | let permissioned_users: HashSet<PublicKey> = [repo_ref.maintainers.clone(), vec![ | 1818 | let permissioned_users: HashSet<PublicKey> = [ |
| 1808 | commit_events | 1819 | repo_ref.maintainers.clone(), |
| 1809 | .iter() | 1820 | vec![ |
| 1810 | .find(|e| e.id.eq(proposal_id)) | 1821 | commit_events |
| 1811 | .context("proposal not in cache")? | 1822 | .iter() |
| 1812 | .pubkey, | 1823 | .find(|e| e.id.eq(proposal_id)) |
| 1813 | ]] | 1824 | .context("proposal not in cache")? |
| 1825 | .pubkey, | ||
| 1826 | ], | ||
| 1827 | ] | ||
| 1814 | .concat() | 1828 | .concat() |
| 1815 | .iter() | 1829 | .iter() |
| 1816 | .copied() | 1830 | .copied() |
| @@ -1824,12 +1838,15 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 1824 | .collect(); | 1838 | .collect(); |
| 1825 | 1839 | ||
| 1826 | if !revision_roots.is_empty() { | 1840 | if !revision_roots.is_empty() { |
| 1827 | for event in get_events_from_local_cache(git_repo_path, vec![ | 1841 | for event in get_events_from_local_cache( |
| 1828 | nostr::Filter::default() | 1842 | git_repo_path, |
| 1829 | .kind(nostr::Kind::GitPatch) | 1843 | vec![ |
| 1830 | .events(revision_roots) | 1844 | nostr::Filter::default() |
| 1831 | .authors(permissioned_users.clone()), | 1845 | .kind(nostr::Kind::GitPatch) |
| 1832 | ]) | 1846 | .events(revision_roots) |
| 1847 | .authors(permissioned_users.clone()), | ||
| 1848 | ], | ||
| 1849 | ) | ||
| 1833 | .await? | 1850 | .await? |
| 1834 | { | 1851 | { |
| 1835 | commit_events.push(event); | 1852 | commit_events.push(event); |
| @@ -1844,9 +1861,10 @@ pub async fn get_all_proposal_patch_events_from_cache( | |||
| 1844 | } | 1861 | } |
| 1845 | 1862 | ||
| 1846 | pub async fn get_event_from_cache_by_id(git_repo: &Repo, event_id: &EventId) -> Result<Event> { | 1863 | pub async fn get_event_from_cache_by_id(git_repo: &Repo, event_id: &EventId) -> Result<Event> { |
| 1847 | Ok(get_events_from_local_cache(git_repo.get_path()?, vec![ | 1864 | Ok(get_events_from_local_cache( |
| 1848 | nostr::Filter::default().id(*event_id), | 1865 | git_repo.get_path()?, |
| 1849 | ]) | 1866 | vec![nostr::Filter::default().id(*event_id)], |
| 1867 | ) | ||
| 1850 | .await? | 1868 | .await? |
| 1851 | .first() | 1869 | .first() |
| 1852 | .context("failed to find event in cache")? | 1870 | .context("failed to find event in cache")? |