Page MenuHomePhabricator

D14145.id46392.diff
No OneTemporary

D14145.id46392.diff

diff --git a/keyserver/src/scripts/get-community-ids.js b/keyserver/src/scripts/get-community-ids.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/scripts/get-community-ids.js
@@ -0,0 +1,47 @@
+// @flow
+
+import { main } from './utils.js';
+import { dbQuery, SQL } from '../database/database.js';
+
+async function fetchCommunityIDsByNames(
+ communityNames: $ReadOnlyArray<string>,
+): Promise<{
+ communityIDs: $ReadOnlyArray<string>,
+ unresolvedNames: $ReadOnlyArray<string>,
+}> {
+ if (communityNames.length === 0) {
+ return { communityIDs: [], unresolvedNames: [] };
+ }
+
+ const query = SQL`
+ SELECT t.name, c.id
+ FROM communities c
+ INNER JOIN threads t
+ ON c.id = t.id
+ WHERE t.name IN (${communityNames})
+ AND c.farcaster_channel_id IS NOT NULL
+ `;
+
+ const [result] = await dbQuery(query);
+
+ const resolvedNames = result.map(row => row.name);
+ const communityIDs = result.map(row => row.id.toString());
+ const unresolvedNames = communityNames.filter(
+ name => !resolvedNames.includes(name),
+ );
+
+ return { communityIDs, unresolvedNames };
+}
+
+async function fetchCommunityIDsByNamesScript() {
+ const communityNames: $ReadOnlyArray<string> = []; // Replace with actual community names
+ const { communityIDs, unresolvedNames } =
+ await fetchCommunityIDsByNames(communityNames);
+ console.log('Fetched Community IDs:', communityIDs);
+
+ if (unresolvedNames.length > 0) {
+ console.log('Unresolved Community Names:', unresolvedNames);
+ }
+}
+
+main([fetchCommunityIDsByNamesScript]);

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 23, 8:32 AM (14 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2692228
Default Alt Text
D14145.id46392.diff (1 KB)

Event Timeline