Skip to content

Commit

Permalink
[keyserver][script] get IDs for community names
Browse files Browse the repository at this point in the history
Summary:
we want to harcode a list of crypto community IDs so that we can display the associated communities in a tab for crypto users. i have a list of crypto community names, and need to turn this into a list of IDs

https://linear.app/comm/issue/ENG-9953/get-list-of-crypto-communities-from-ashoat-and-rahul

Test Plan: ran this locally with a couple community names and got back the corresponding IDs

Reviewers: ashoat

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D14145
  • Loading branch information
vdhanan committed Dec 12, 2024
1 parent cb47dbd commit 459ec03
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions keyserver/src/scripts/get-community-ids.js
Original file line number Diff line number Diff line change
@@ -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]);

0 comments on commit 459ec03

Please sign in to comment.