Skip to content

Commit

Permalink
[keyserver] Fix up get-community-ids.js script
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashoat committed Dec 14, 2024
1 parent 7c243cc commit 9d08a8b
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions keyserver/src/scripts/get-community-ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,49 @@
import { main } from './utils.js';
import { dbQuery, SQL } from '../database/database.js';

async function fetchCommunityIDsByNames(
communityNames: $ReadOnlyArray<string>,
async function fetchCommCommunityIDsByFarcasterChannelIDs(
farcasterChannelIDs: $ReadOnlyArray<string>,
): Promise<{
communityIDs: $ReadOnlyArray<string>,
unresolvedNames: $ReadOnlyArray<string>,
unresolvedFarcasterChannelIDs: $ReadOnlyArray<string>,
}> {
if (communityNames.length === 0) {
return { communityIDs: [], unresolvedNames: [] };
if (farcasterChannelIDs.length === 0) {
return { communityIDs: [], unresolvedFarcasterChannelIDs: [] };
}

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
SELECT id, farcaster_channel_id
FROM communities
WHERE farcaster_channel_id IN (${farcasterChannelIDs})
`;

const [result] = await dbQuery(query);

const resolvedNames = result.map(row => row.name);
const resolvedFarcasterChannelIDs = result.map(
row => row.farcaster_channel_id,
);
const communityIDs = result.map(row => row.id.toString());
const unresolvedNames = communityNames.filter(
name => !resolvedNames.includes(name),
const unresolvedFarcasterChannelIDs = farcasterChannelIDs.filter(
farcasterChannelID =>
!resolvedFarcasterChannelIDs.includes(farcasterChannelID),
);

return { communityIDs, unresolvedNames };
return { communityIDs, unresolvedFarcasterChannelIDs };
}

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

if (unresolvedFarcasterChannelIDs.length > 0) {
console.log(
'Unresolved Farcaster channel IDs:',
unresolvedFarcasterChannelIDs,
);
}
}

main([fetchCommunityIDsByNamesScript]);
main([fetchCommunityIDsByFarcasterChannelIDsScript]);

0 comments on commit 9d08a8b

Please sign in to comment.