Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3515333
D14145.id46392.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D14145.id46392.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D14145: [keyserver][script] get IDs for community names
Attached
Detach File
Event Timeline
Log In to Comment