Skip to content

Commit

Permalink
Rename profile to account for v3 preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoginth committed Nov 23, 2024
1 parent 399f8cf commit d7c21d0
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 43 deletions.
8 changes: 4 additions & 4 deletions apps/api/src/routes/misc/verified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ export const get = [
const cachedData = await getRedis(cacheKey);

if (cachedData) {
logger.info("(cached) Verified profiles fetched");
logger.info("(cached) Verified accounts fetched");
return res
.status(200)
.setHeader("Cache-Control", CACHE_AGE_30_MINS)
.json({ result: JSON.parse(cachedData), success: true });
}

const profilePermission = await prisma.profilePermission.findMany({
const accountPermission = await prisma.profilePermission.findMany({
select: { profileId: true },
where: { enabled: true, permissionId: PermissionId.Verified }
});

const result = profilePermission.map(({ profileId }) => profileId);
const result = accountPermission.map(({ profileId }) => profileId);
await setRedis(cacheKey, result);
logger.info("Verified profiles fetched");
logger.info("Verified accounts fetched");

return res
.status(200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { buildSitemapXml } from "src/helpers/sitemap/buildSitemap";

export const get = async (req: Request, res: Response) => {
const userAgent = req.headers["user-agent"];
const redisKey = "sitemap:profiles:total";
const redisKey = "sitemap:accounts:total";

try {
const cachedData = await getRedis(redisKey);
Expand All @@ -33,12 +33,12 @@ export const get = async (req: Request, res: Response) => {

const totalBatches = Math.ceil(totalHandles / SITEMAP_BATCH_SIZE);
const entries = Array.from({ length: totalBatches }, (_, index) => ({
loc: `https://api.hey.xyz/sitemap/profiles/${index + 1}.xml`
loc: `https://api.hey.xyz/sitemap/accounts/${index + 1}.xml`
}));
const xml = buildSitemapXml(entries);

logger.info(
`[Lens] Fetched all profiles sitemap index having ${totalBatches} batches from user-agent: ${userAgent}`
`[Lens] Fetched all accounts sitemap index having ${totalBatches} batches from user-agent: ${userAgent}`
);

return res
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const get = async (req: Request, res: Response) => {
}

const userAgent = req.headers["user-agent"];
const redisKey = `sitemap:profiles:batch:${id}`;
const redisKey = `sitemap:accounts:batch:${id}`;

try {
const cachedData = await getRedis(redisKey);
Expand All @@ -33,7 +33,7 @@ export const get = async (req: Request, res: Response) => {
if (cachedData) {
entries = JSON.parse(cachedData);
logger.info(
`(cached) [Lens] Fetched profiles sitemap for batch ${id} having ${entries.length} entries from user-agent: ${userAgent}`
`(cached) [Lens] Fetched accounts sitemap for batch ${id} having ${entries.length} entries from user-agent: ${userAgent}`
);
} else {
const offset = (Number(id) - 1) * SITEMAP_BATCH_SIZE || 0;
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/routes/sitemap/sitemap.xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const get = async (req: Request, res: Response) => {
try {
const sitemaps = [
"https://api.hey.xyz/sitemap/posts.xml",
"https://api.hey.xyz/sitemap/profiles.xml",
"https://api.hey.xyz/sitemap/accounts.xml",
"https://api.hey.xyz/sitemap/others.xml"
];

Expand Down
2 changes: 1 addition & 1 deletion apps/api/tests/misc/verified.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { TEST_URL } from "tests/helpers/constants";
import { describe, expect, test } from "vitest";

describe("GET /misc/verified", () => {
test("should return 200 and fetch the verified profiles", async () => {
test("should return 200 and fetch the verified accounts", async () => {
const { data, status } = await axios.get(`${TEST_URL}/misc/verified`);

expect(status).toBe(200);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import axios from "axios";
import { TEST_URL } from "tests/helpers/constants";
import { describe, expect, test, vi } from "vitest";

describe("GET /sitemap/profiles.xml", () => {
test("should return 200 and generate a sitemap with profile links", async () => {
describe("GET /sitemap/accounts.xml", () => {
test("should return 200 and generate a sitemap with account links", async () => {
const mockCount = 1000;
const SITEMAP_BATCH_SIZE = 100;
vi.spyOn(lensPg, "query").mockResolvedValueOnce([{ count: mockCount }]);

const { data, status, headers } = await axios.get(
`${TEST_URL}/sitemap/profiles.xml`
`${TEST_URL}/sitemap/accounts.xml`
);

expect(status).toBe(200);
Expand All @@ -20,7 +20,7 @@ describe("GET /sitemap/profiles.xml", () => {

for (let i = 1; i <= totalBatches; i++) {
expect(data).toContain(
`<loc>https://api.hey.xyz/sitemap/profiles/${i}.xml</loc>`
`<loc>https://api.hey.xyz/sitemap/accounts/${i}.xml</loc>`
);
}
});
Expand All @@ -29,7 +29,7 @@ describe("GET /sitemap/profiles.xml", () => {
vi.spyOn(lensPg, "query").mockRejectedValueOnce(new Error("DB Error"));

try {
await axios.get(`${TEST_URL}/sitemap/profiles.xml`);
await axios.get(`${TEST_URL}/sitemap/accounts.xml`);
} catch (error: any) {
expect(error.response.status).toBe(500);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/public/opensearch.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>Hey</ShortName>
<Description>Hey Search</Description>
<Url type="text/html" method="get" template="https://hey.xyz/search?q={searchTerms}&#38;type=profiles"/>
<Url type="text/html" method="get" template="https://hey.xyz/search?q={searchTerms}&#38;type=accounts"/>
<Image width="32" height="32">https://hey.xyz/32x32.png</Image>
<InputEncoding>UTF-8</InputEncoding>
<moz:SearchForm>https://hey.xyz</moz:SearchForm>
Expand Down
38 changes: 19 additions & 19 deletions apps/web/src/components/Account/MutualFollowersOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const MutualFollowersOverview: FC<MutualFollowersOverviewProps> = ({
}
});

const profiles =
const accounts =
(data?.mutualFollowers?.items.slice(0, 4) as Profile[]) || [];

const Wrapper = ({ children }: { children: ReactNode }) => (
Expand All @@ -49,7 +49,7 @@ const MutualFollowersOverview: FC<MutualFollowersOverviewProps> = ({
type="button"
>
<StackedAvatars
avatars={profiles.map((profile) => getAvatar(profile))}
avatars={accounts.map((account) => getAvatar(account))}
limit={3}
/>
<div className="text-left">
Expand All @@ -70,43 +70,43 @@ const MutualFollowersOverview: FC<MutualFollowersOverviewProps> = ({
</button>
);

if (profiles.length === 0 || loading || error) {
if (accounts.length === 0 || loading || error) {
return null;
}

const profileOne = profiles[0];
const profileTwo = profiles[1];
const profileThree = profiles[2];
const accountOne = accounts[0];
const accountTwo = accounts[1];
const accountThree = accounts[2];

if (profiles?.length === 1) {
if (accounts?.length === 1) {
return (
<Wrapper>
<span>{getAccount(profileOne).displayName}</span>
<span>{getAccount(accountOne).displayName}</span>
</Wrapper>
);
}

if (profiles?.length === 2) {
if (accounts?.length === 2) {
return (
<Wrapper>
<span>{getAccount(profileOne).displayName} and </span>
<span>{getAccount(profileTwo).displayName}</span>
<span>{getAccount(accountOne).displayName} and </span>
<span>{getAccount(accountTwo).displayName}</span>
</Wrapper>
);
}

if (profiles?.length === 3) {
const calculatedCount = profiles.length - 3;
if (accounts?.length === 3) {
const calculatedCount = accounts.length - 3;
const isZero = calculatedCount === 0;

return (
<Wrapper>
<span>{getAccount(profileOne).displayName}, </span>
<span>{getAccount(accountOne).displayName}, </span>
<span>
{getAccount(profileTwo).displayName}
{getAccount(accountTwo).displayName}
{isZero ? " and " : ", "}
</span>
<span>{getAccount(profileThree).displayName} </span>
<span>{getAccount(accountThree).displayName} </span>
{isZero ? null : (
<span>
and {calculatedCount} {calculatedCount === 1 ? "other" : "others"}
Expand All @@ -118,9 +118,9 @@ const MutualFollowersOverview: FC<MutualFollowersOverviewProps> = ({

return (
<Wrapper>
<span>{getAccount(profileOne).displayName}, </span>
<span>{getAccount(profileTwo).displayName}, </span>
<span>{getAccount(profileThree).displayName} </span>
<span>{getAccount(accountOne).displayName}, </span>
<span>{getAccount(accountTwo).displayName}, </span>
<span>{getAccount(accountThree).displayName} </span>
<span>and others</span>
</Wrapper>
);
Expand Down
14 changes: 7 additions & 7 deletions apps/web/src/components/Home/Timeline/EventType/Mirrored.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ interface MirroredProps {
}

const Mirrored: FC<MirroredProps> = ({ mirrors }) => {
const getMirroredProfiles = () => {
let profiles = mirrors.map((mirror) => mirror.by);
profiles = profiles.filter(
(profile, index, self) =>
index === self.findIndex((t) => t.id === profile.id)
const getMirroredAccounts = () => {
let accounts = mirrors.map((mirror) => mirror.by);
accounts = accounts.filter(
(account, index, self) =>
index === self.findIndex((t) => t.id === account.id)
);
return profiles;
return accounts;
};

return (
<div className="ld-text-gray-500 mb-3 flex items-center space-x-1 text-[13px]">
<ArrowsRightLeftIcon className="size-4" />
<Accounts context="mirrored" accounts={getMirroredProfiles()} />
<Accounts context="mirrored" accounts={getMirroredAccounts()} />
</div>
);
};
Expand Down

1 comment on commit d7c21d0

@vercel
Copy link

@vercel vercel bot commented on d7c21d0 Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web – ./

web-git-main-heyxyz.vercel.app
heyxyz.vercel.app
web-heyxyz.vercel.app
hey.xyz

Please sign in to comment.