Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

Compare changes

Choose any two refs to compare.

+9 -9
Cargo.lock
···
[[package]]
name = "clap"
-
version = "4.5.47"
+
version = "4.5.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "7eac00902d9d136acd712710d71823fb8ac8004ca445a89e73a41d45aa712931"
+
checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae"
dependencies = [
"clap_builder",
"clap_derive",
···
[[package]]
name = "clap_builder"
-
version = "4.5.47"
+
version = "4.5.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "2ad9bbf750e73b5884fb8a211a9424a1906c1e156724260fdae972f31d70e1d6"
+
checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9"
dependencies = [
"anstream",
"anstyle",
···
checksum = "18e4fdb82bd54a12e42fb58a800dcae6b9e13982238ce2296dc3570b92148e1f"
dependencies = [
"data-encoding",
-
"syn 1.0.109",
+
"syn 2.0.106",
[[package]]
···
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
dependencies = [
"cfg-if",
-
"windows-targets 0.48.5",
+
"windows-targets 0.52.6",
[[package]]
···
[[package]]
name = "reqwest"
-
version = "0.12.22"
+
version = "0.12.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
-
checksum = "cbc931937e6ca3a06e3b6c0aa7841849b160a90351d6ab467a8b9b9959767531"
+
checksum = "d429f34c8092b2d42c7c93cec323bb4adeb7c67698f70839adec842ec10c7ceb"
dependencies = [
"async-compression",
"base64 0.22.1",
···
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
-
"windows-sys 0.48.0",
+
"windows-sys 0.59.0",
[[package]]
+1 -1
constellation/src/bin/main.rs
···
let rocks = rocks.clone();
let stay_alive = stay_alive.clone();
s.spawn(move || {
-
let rep = rocks.run_repair(time::Duration::from_millis(1), stay_alive);
+
let rep = rocks.run_repair(time::Duration::from_millis(0), stay_alive);
eprintln!("repair finished: {rep:?}");
rep
});
+4
constellation/src/server/filters.rs
···
pub fn human_number(n: &u64) -> askama::Result<String> {
Ok(n.to_formatted_string(&Locale::en))
}
+
+
pub fn to_u64(n: usize) -> askama::Result<u64> {
+
Ok(n as u64)
+
}
+3 -1
constellation/src/server/mod.rs
···
};
let path = format!(".{path}");
+
let path_to_other = format!(".{}", query.path_to_other);
+
let paged = store
.get_many_to_many_counts(
&query.subject,
collection,
&path,
-
&query.path_to_other,
+
&path_to_other,
limit,
cursor_key,
&filter_dids,
+7 -1
constellation/src/storage/rocks_store.rs
···
let mut maybe_done = false;
+
let mut write_fast = rocksdb::WriteOptions::default();
+
write_fast.set_sync(false);
+
write_fast.disable_wal(true);
+
while !stay_alive.is_cancelled() && !maybe_done {
// let mut batch = WriteBatch::default();
···
let target_id: TargetId = _vr(iter.value().unwrap())?;
self.db
-
.put_cf(&cf, target_id.id().to_be_bytes(), _rv(&target))?;
+
.put_cf_opt(&cf, target_id.id().to_be_bytes(), _rv(&target), &write_fast)?;
any_written = true;
iter.next();
}
···
let after = after.map(|s| s.parse::<u64>().map(TargetId)).transpose()?;
let Some(target_id) = self.target_id_table.get_id_val(&self.db, &target_key)? else {
+
eprintln!("nothin doin for this target, {target_key:?}");
return Ok(Default::default());
};
···
.take(1)
.next()
else {
+
eprintln!("no forward match");
continue;
};
+1 -1
constellation/templates/get-backlinks.html.j2
···
{% extends "base.html.j2" %}
{% import "try-it-macros.html.j2" as try_it %}
-
{% block title %}Links{% endblock %}
+
{% block title %}Backlinks{% endblock %}
{% block description %}All {{ query.source }} records with links to {{ query.subject }}{% endblock %}
{% block content %}
+67
constellation/templates/get-many-to-many-counts.html.j2
···
+
{% extends "base.html.j2" %}
+
{% import "try-it-macros.html.j2" as try_it %}
+
+
{% block title %}Many to Many counts{% endblock %}
+
{% block description %}Counts of many-to-many {{ query.source }} join records with links to {{ query.subject }} and a secondary target at {{ query.path_to_other }}{% endblock %}
+
+
{% block content %}
+
+
{% call try_it::get_many_to_many_counts(
+
query.subject,
+
query.source,
+
query.path_to_other,
+
query.did,
+
query.other_subject,
+
query.limit,
+
) %}
+
+
<h2>
+
Many-to-many links to <code>{{ query.subject }}</code> joining through <code>{{ query.path_to_other }}</code>
+
{% if let Some(browseable_uri) = query.subject|to_browseable %}
+
<small style="font-weight: normal; font-size: 1rem"><a href="{{ browseable_uri }}">browse record</a></small>
+
{% endif %}
+
</h2>
+
+
<p><strong>{% if cursor.is_some() || query.cursor.is_some() %}more than {% endif %}{{ counts_by_other_subject.len()|to_u64|human_number }} joins</strong> <code>{{ query.source }}โ†’{{ query.path_to_other }}</code></p>
+
+
<ul>
+
<li>See direct backlinks at <code>/xrpc/blue.microcosm.links.getBacklinks</code>: <a href="/xrpc/blue.microcosm.links.getBacklinks?subject={{ query.subject|urlencode }}&source={{ query.source|urlencode }}">/xrpc/blue.microcosm.links.getBacklinks?subject={{ query.subject }}&source={{ query.source }}</a></li>
+
<li>See all links to this target at <code>/links/all</code>: <a href="/links/all?target={{ query.subject|urlencode }}">/links/all?target={{ query.subject }}</a></li>
+
</ul>
+
+
<h3>Counts by other subject:</h3>
+
+
{% for counts in counts_by_other_subject %}
+
<pre style="display: block; margin: 1em 2em" class="code"><strong>Joined subject</strong>: {{ counts.subject }}
+
<strong>Joining records</strong>: {{ counts.total }}
+
<strong>Unique joiner ids</strong>: {{ counts.distinct }}
+
-> {% if let Some(browseable_uri) = counts.subject|to_browseable -%}
+
<a href="{{ browseable_uri }}">browse record</a>
+
{%- endif %}</pre>
+
{% endfor %}
+
+
{% if let Some(c) = cursor %}
+
<form method="get" action="/xrpc/blue.microcosm.links.getManyToManyCounts">
+
<input type="hidden" name="subject" value="{{ query.subject }}" />
+
<input type="hidden" name="source" value="{{ query.source }}" />
+
<input type="hidden" name="pathToOther" value="{{ query.path_to_other }}" />
+
{% for did in query.did %}
+
<input type="hidden" name="did" value="{{ did }}" />
+
{% endfor %}
+
{% for otherSubject in query.other_subject %}
+
<input type="hidden" name="otherSubject" value="{{ otherSubject }}" />
+
{% endfor %}
+
<input type="hidden" name="limit" value="{{ query.limit }}" />
+
<input type="hidden" name="cursor" value={{ c|json|safe }} />
+
<button type="submit">next page&hellip;</button>
+
</form>
+
{% else %}
+
<button disabled><em>end of results</em></button>
+
{% endif %}
+
+
<details>
+
<summary>Raw JSON response</summary>
+
<pre class="code">{{ self|tojson }}</pre>
+
</details>
+
+
{% endblock %}
+26
constellation/templates/hello.html.j2
···
{% call try_it::get_backlinks("at://did:plc:a4pqq234yw7fqbddawjo7y35/app.bsky.feed.post/3m237ilwc372e", "app.bsky.feed.like:subject.uri", [""], 16) %}
+
<h3 class="route"><code>GET /xrpc/blue.microcosm.links.getManyToManyCounts</code></h3>
+
+
<p>TODO: description</p>
+
+
<h4>Query parameters:</h4>
+
+
<ul>
+
<li><p><code>subject</code>: required, must url-encode. Example: <code>at://did:plc:vc7f4oafdgxsihk4cry2xpze/app.bsky.feed.post/3lgwdn7vd722r</code></p></li>
+
<li><p><code>source</code>: required. Example: <code>app.bsky.feed.like:subject.uri</code></p></li>
+
<li><p><code>pathToOther</code>: required. Path to the secondary link in the many-to-many record. Example: <code>otherThing.uri</code></p></li>
+
<li><p><code>did</code>: optional, filter links to those from specific users. Include multiple times to filter by multiple users. Example: <code>did=did:plc:vc7f4oafdgxsihk4cry2xpze&did=did:plc:vc7f4oafdgxsihk4cry2xpze</code></p></li>
+
<li><p><code>otherSubject</code>: optional, filter secondary links to specific subjects. Include multiple times to filter by multiple users. Example: <code>at://did:plc:vc7f4oafdgxsihk4cry2xpze/app.bsky.feed.post/3lgwdn7vd722r</code></p></li>
+
<li><p><code>limit</code>: optional. Default: <code>16</code>. Maximum: <code>100</code></p></li>
+
</ul>
+
+
<p style="margin-bottom: 0"><strong>Try it:</strong></p>
+
{% call try_it::get_many_to_many_counts(
+
"at://did:plc:wshs7t2adsemcrrd4snkeqli/sh.tangled.label.definition/good-first-issue",
+
"sh.tangled.label.op:add[].key",
+
"subject",
+
[""],
+
[""],
+
25,
+
) %}
+
+
<h3 class="route"><code>GET /links</code></h3>
<p>A list of records linking to a target.</p>
+43 -1
constellation/templates/try-it-macros.html.j2
···
{% macro get_backlinks(subject, source, dids, limit) %}
<form method="get" action="/xrpc/blue.microcosm.links.getBacklinks">
-
<pre class="code"><strong>GET</strong> /links
+
<pre class="code"><strong>GET</strong> /xrpc/blue.microcosm.links.getBacklinks
?subject= <input type="text" name="subject" value="{{ subject }}" placeholder="at-uri, did, uri..." />
&source= <input type="text" name="source" value="{{ source }}" placeholder="app.bsky.feed.like:subject.uri" />
{%- for did in dids %}{% if !did.is_empty() %}
···
p.insertBefore(document.createTextNode('&did= '), didPlaceholder);
p.insertBefore(i, didPlaceholder);
p.insertBefore(document.createTextNode('\n '), didPlaceholder);
+
});
+
</script>
+
{% endmacro %}
+
+
{% macro get_many_to_many_counts(subject, source, pathToOther, dids, otherSubjects, limit) %}
+
<form method="get" action="/xrpc/blue.microcosm.links.getManyToManyCounts">
+
<pre class="code"><strong>GET</strong> /xrpc/blue.microcosm.links.getManyToManyCounts
+
?subject= <input type="text" name="subject" value="{{ subject }}" placeholder="at-uri, did, uri..." />
+
&source= <input type="text" name="source" value="{{ source }}" placeholder="app.bsky.feed.like:subject.uri" />
+
&pathToOther= <input type="text" name="pathToOther" value="{{ pathToOther }}" placeholder="otherThing.uri" />
+
{%- for did in dids %}{% if !did.is_empty() %}
+
&did= <input type="text" name="did" value="{{ did }}" placeholder="did:plc:..." />{% endif %}{% endfor %}
+
<span id="m2m-subject-placeholder"></span> <button id="m2m-add-subject">+ other subject filter</button>
+
{%- for otherSubject in otherSubjects %}{% if !otherSubject.is_empty() %}
+
&otherSubject= <input type="text" name="did" value="{{ otherSubject }}" placeholder="at-uri, did, uri..." />{% endif %}{% endfor %}
+
<span id="m2m-did-placeholder"></span> <button id="m2m-add-did">+ did filter</button>
+
&limit= <input type="number" name="limit" value="{{ limit }}" max="100" placeholder="100" /> <button type="submit">get links</button></pre>
+
</form>
+
<script>
+
const m2mAddDidButton = document.getElementById('m2m-add-did');
+
const m2mDidPlaceholder = document.getElementById('m2m-did-placeholder');
+
m2mAddDidButton.addEventListener('click', e => {
+
e.preventDefault();
+
const i = document.createElement('input');
+
i.placeholder = 'did:plc:...';
+
i.name = "did"
+
const p = m2mAddDidButton.parentNode;
+
p.insertBefore(document.createTextNode('&did= '), m2mDidPlaceholder);
+
p.insertBefore(i, m2mDidPlaceholder);
+
p.insertBefore(document.createTextNode('\n '), m2mDidPlaceholder);
+
});
+
const m2mAddSubjectButton = document.getElementById('m2m-add-subject');
+
const m2mSubjectPlaceholder = document.getElementById('m2m-subject-placeholder');
+
m2mAddSubjectButton.addEventListener('click', e => {
+
e.preventDefault();
+
const i = document.createElement('input');
+
i.placeholder = 'at-uri, did, uri...';
+
i.name = "otherSubject"
+
const p = m2mAddSubjectButton.parentNode;
+
p.insertBefore(document.createTextNode('&otherSubject= '), m2mSubjectPlaceholder);
+
p.insertBefore(i, m2mSubjectPlaceholder);
+
p.insertBefore(document.createTextNode('\n '), m2mSubjectPlaceholder);
});
</script>
{% endmacro %}