Skip to content

Commit d3ef7ae

Browse files
authored
Merge pull request #11 from AOSC-Dev/sorevdeps
feat: add so revdeps on revdeps page
2 parents 392fa2d + d825a15 commit d3ef7ae

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

src/sql.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,3 +775,32 @@ WHERE
775775
ORDER BY
776776
package
777777
";
778+
779+
pub const SQL_GET_PACKAGE_SO_REVDEPS: &str = "
780+
SELECT
781+
DISTINCT s.name, s.package
782+
FROM
783+
pv_package_sodep s
784+
INNER JOIN (
785+
SELECT
786+
p.name, p.ver
787+
FROM
788+
pv_package_sodep p
789+
INNER JOIN
790+
v_packages_new n
791+
ON
792+
p.package = n.package
793+
AND p.version = n.version
794+
WHERE
795+
p.package = $1
796+
AND p.depends = 0
797+
AND p.ver IS NOT NULL
798+
) n
799+
ON
800+
s.name = n.name
801+
AND s.ver = n.ver
802+
WHERE
803+
s.depends = 1
804+
ORDER BY
805+
s.name, s.package
806+
";

src/views/package.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ pub async fn revdep(Revdep { name }: Revdep, q: Query, db: Ext) -> Result<impl I
453453
revdeps: &'a Vec<TemplateRevDep<'a>>,
454454
sobreaks: &'a Vec<Vec<String>>,
455455
sobreaks_circular: &'a Vec<String>,
456+
sorevdeps: &'a HashMap<String, Vec<String>>,
456457
}
457458

458459
#[derive(Debug, Template, Serialize)]
@@ -461,6 +462,7 @@ pub async fn revdep(Revdep { name }: Revdep, q: Query, db: Ext) -> Result<impl I
461462
revdeps: &'a Vec<TemplateRevDep<'a>>,
462463
sobreaks: &'a Vec<Vec<String>>,
463464
sobreaks_circular: &'a Vec<String>,
465+
sorevdeps: &'a HashMap<String, Vec<String>>,
464466
}
465467

466468
#[derive(Debug, FromRow)]
@@ -545,17 +547,29 @@ pub async fn revdep(Revdep { name }: Revdep, q: Query, db: Ext) -> Result<impl I
545547

546548
let (ref sobreaks, ref sobreaks_circular) = toposort(sobreaks);
547549

550+
let sorevdeps: Vec<(String, String)> = query_as(SQL_GET_PACKAGE_SO_REVDEPS)
551+
.bind(&name)
552+
.fetch_all(&db.pv)
553+
.await?;
554+
555+
let mut sorevdeps_grouped: HashMap<String, Vec<String>> = HashMap::new();
556+
for (k, v) in sorevdeps {
557+
sorevdeps_grouped.entry(k).or_insert_with(Vec::new).push(v);
558+
}
559+
548560
let ctx = Template {
549561
name: &name,
550562
revdeps,
551563
sobreaks,
552564
sobreaks_circular,
565+
sorevdeps: &sorevdeps_grouped,
553566
};
554567

555568
let ctx_tsv = TemplateTsv {
556569
revdeps,
557570
sobreaks,
558571
sobreaks_circular,
572+
sorevdeps: &sorevdeps_grouped,
559573
};
560574

561575
render(ctx, Some(ctx_tsv), &q)

templates/revdep.html

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,16 @@
3636
</ul>
3737
{% endif %}
3838

39-
{% endblock main %}
39+
{% if !sorevdeps.is_empty() -%}<p><b class="pkg-field">Reverse dependencies of
40+
the libraries</b>:
41+
<ul>{% for library in sorevdeps.keys() -%}
42+
<li>{{ library }}:
43+
{% for package in sorevdeps.get(library.as_str()).unwrap() -%}
44+
{% if loop.index != 1 %},{% endif %}
45+
<span class="pkg-dep"><a href="{{ package }}">{{ package }}</a></span>
46+
{%- endfor %}
47+
</li>{%- endfor %}
48+
</ul>
49+
{% endif %}
50+
51+
{% endblock main %}

templates/revdep.tsv

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ SOBREAK {{ outer }} {{ package }}
99
{% endfor %}{% endfor %}{% if !sobreaks_circular.is_empty() -%}
1010
{% for package in sobreaks_circular -%}
1111
SOBREAK {{ package }}
12-
{% endfor %}{% endif %}{% endif %}
12+
{% endfor %}{% endif %}{% endif %}{% if !sorevdeps.is_empty() -%}
13+
{% for library in sorevdeps.keys() -%}{% for package in sorevdeps.get(library.as_str()).unwrap() -%}
14+
SOREVDEP {{ library }} {{ package }}
15+
{% endfor %}{% endfor %}{% endif %}

0 commit comments

Comments
 (0)