Skip to content

Commit

Permalink
[keyserver][script] update script to return tuple of community ID and…
Browse files Browse the repository at this point in the history
… farcaster channel ID

Summary: we want the mapping from community to farcaster channel ID so we can determine which community IDs to promote in the community directory

Test Plan: successfully returned tuples

Reviewers: ashoat

Reviewed By: ashoat

Subscribers: tomek

Differential Revision: https://phab.comm.dev/D14197
  • Loading branch information
vdhanan authored and Ashoat committed Jan 10, 2025
1 parent 0664539 commit 2c2d193
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions keyserver/src/scripts/get-community-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { dbQuery, SQL } from '../database/database.js';
async function fetchCommCommunityIDsByFarcasterChannelIDs(
farcasterChannelIDs: $ReadOnlyArray<string>,
): Promise<{
communityIDs: $ReadOnlyArray<string>,
communityMappings: $ReadOnlyArray<[string, string]>,
unresolvedFarcasterChannelIDs: $ReadOnlyArray<string>,
}> {
if (farcasterChannelIDs.length === 0) {
return { communityIDs: [], unresolvedFarcasterChannelIDs: [] };
return { communityMappings: [], unresolvedFarcasterChannelIDs: [] };
}

const query = SQL`
Expand All @@ -24,21 +24,28 @@ async function fetchCommCommunityIDsByFarcasterChannelIDs(
const resolvedFarcasterChannelIDs = result.map(
row => row.farcaster_channel_id,
);
const communityIDs = result.map(row => row.id.toString());
const communityMappings = result.map(row => [
row.farcaster_channel_id,
row.id.toString(),
]);
const unresolvedFarcasterChannelIDs = farcasterChannelIDs.filter(
farcasterChannelID =>
!resolvedFarcasterChannelIDs.includes(farcasterChannelID),
);

return { communityIDs, unresolvedFarcasterChannelIDs };
return { communityMappings, unresolvedFarcasterChannelIDs };
}

async function fetchCommunityIDsByFarcasterChannelIDsScript() {
// Replace with actual community names
// Replace with actual Farcaster channel IDs
const farcasterChannelIDs: $ReadOnlyArray<string> = [];
const { communityIDs, unresolvedFarcasterChannelIDs } =
const { communityMappings, unresolvedFarcasterChannelIDs } =
await fetchCommCommunityIDsByFarcasterChannelIDs(farcasterChannelIDs);
console.log('Comm community IDs:', communityIDs);

console.log('Comm community ID mappings (FarcasterChannelID, CommunityID):');
communityMappings.forEach(([farcasterChannelID, communityID]) =>
console.log(`(${farcasterChannelID}, ${communityID})`),
);

if (unresolvedFarcasterChannelIDs.length > 0) {
console.log(
Expand Down

0 comments on commit 2c2d193

Please sign in to comment.