Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve membersURI #812

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a386393
improve membersURI
Rashmi-278 Feb 26, 2024
3e5bf86
add limit, pagination and uniqueness check for members
Rashmi-278 Mar 6, 2024
231b6b3
updated approach, get all unique addresses from DB
Rashmi-278 Apr 22, 2024
b828ed3
remove angle brackets from context link
Rashmi-278 Apr 22, 2024
51c4294
add context
Rashmi-278 Apr 22, 2024
7ebe8c7
Update .gitignore
Rashmi-278 May 1, 2024
ac8669b
Update src/eip4824.ts
Rashmi-278 May 1, 2024
9d41dd3
lint
Rashmi-278 May 1, 2024
47e6eb0
requested changes
Rashmi-278 May 1, 2024
a35202b
Merge remote changes into improve-membersURI
Rashmi-278 May 1, 2024
458e794
remove pnpm
Rashmi-278 May 2, 2024
9849c0b
optimize query for speedy retrival
Rashmi-278 Jun 17, 2024
e342770
Exclude known addresses to optimize for speed
Rashmi-278 Jun 17, 2024
252acc3
remove comments
Rashmi-278 Jun 17, 2024
1df3050
Update src/helpers/spaces.ts
Rashmi-278 Jun 18, 2024
1da8ee9
Update src/helpers/spaces.ts
Rashmi-278 Jun 18, 2024
b2c10b8
cursor conditional
Rashmi-278 Jul 1, 2024
0ce6028
Merge branch 'snapshot-labs:master' into improve-membersURI
Rashmi-278 Jul 1, 2024
240ed25
apply changes
Rashmi-278 Jul 1, 2024
1cd13f3
apply changes
Rashmi-278 Jul 1, 2024
ad86432
cursor conditions
Rashmi-278 Jul 1, 2024
3ca9efa
query improved
Rashmi-278 Aug 21, 2024
560a182
Merge branch 'master' into improve-membersURI
Rashmi-278 Aug 21, 2024
d285d3b
Merge branch 'snapshot-labs:master' into improve-membersURI
Rashmi-278 Aug 21, 2024
f96bf1d
Update eip4824.ts
Rashmi-278 Aug 21, 2024
84d905e
lint
Rashmi-278 Aug 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/eip4824.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from 'express';
import { getSpace } from './helpers/spaces';
import { getSpace, getUniqueVotersForSpace } from './helpers/spaces';
import db, { sequencerDB } from './helpers/mysql';

const router = express.Router();
Expand Down Expand Up @@ -35,21 +35,26 @@ router.get('/:space', async (req, res) => {

router.get('/:space/members', async (req, res) => {
let space: any = {};
let uniqueVoters: any = [];

try {
space = await getSpace(req.params.space);
uniqueVoters = await getUniqueVotersForSpace(req.params.space);

if (!space.verified) return res.status(400).json({ error: 'INVALID' });
} catch (e) {
return res.status(404).json({ error: 'NOT_FOUND' });
}

const members = [...space.admins, ...space.moderators, ...space.members].map(
ChaituVR marked this conversation as resolved.
Show resolved Hide resolved
member => ({
type: 'EthereumAddress',
id: member
})
);
const members = [
...space.admins,
...space.moderators,
...space.members,
...uniqueVoters
].map(member => ({
type: member.type,
id: member.id
}));

return res.json({
'@context': context,
Expand Down
17 changes: 17 additions & 0 deletions src/helpers/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,23 @@ async function getVotes() {
return await db.queryAsync(query);
}

export async function getUniqueVotersForSpace(spaceId) {
const query = `
SELECT space, GROUP_CONCAT(DISTINCT voter) AS unique_voters
FROM votes
WHERE space = ?
GROUP BY space
`;
Rashmi-278 marked this conversation as resolved.
Show resolved Hide resolved
const [result] = await db.queryAsync(query, [spaceId]);

if (!result) return Promise.reject(new Error('NOT_FOUND'));

const votersArray = result.unique_voters ? result.unique_voters.split(',') : [];

return votersArray;
}


async function getFollowers() {
const query = `
SELECT space, COUNT(id) as count,
Expand Down