queen-raae / prune-your-follows

15 stars 1 forks source link

Usage statistics section on marketing page #43

Closed raae closed 1 year ago

raae commented 1 year ago

It would be cool to pull in the number of unfollowed across users and the number of users for a little statistics section on the marketing page.

raae commented 1 year ago

For reference, something like this, but with our numbers!

CleanShot 2022-12-05 at 09 58 26@2x
olavea commented 1 year ago

  const { actions, reporter, createContentDigest, createNodeId } = gatsbyUtils;
  const { createNode } = actions;

  createNode({
    id: createNodeId("statistics"),
    unfollowedCount: 10,
    userCount: 10,
    internal: {
      type: "statistics",
      contentDigest: createContentDigest(10),
    },
  });
raae commented 1 year ago

To get the number from Xata (in localhost these will be very small):

const xata = getXataClient();

const result = await xata.db.accounts.aggregate({
  unfollowsTotal: {
    count: {
      filter: {
        unfollowed: { $ge: new Date("2022-11-03") },
      },
    },
  },
  usersTotal: {
    uniqueCount: {
      column: "followed_by",
    },
  },
});

const unfollowsTotal = result.aggs.unfollowsTotal
const usersTotal = result.aggs.usersTotal

// Use unfollowsTotal and usersTotal when creating the node