Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fixed pagination bug

Steven Tey7d7038c8f082
diff --git a/apps/web/scripts/bulk-create-links.ts b/apps/web/scripts/bulk-create-links.ts
new file mode 100644
index 0000000000..fbab5ba869
--- /dev/null
+++ b/apps/web/scripts/bulk-create-links.ts
@@ -0,0 +1,37 @@
+import "dotenv-flow/config";
+import * as Papa from "papaparse";
+import * as fs from "fs";
+import { redis } from "./utils";
+import { qstash } from "@/lib/cron";
+
+const projectId = "xxx";
+const userId = "xxx";
+const domain = "xxx";
+const links: { domain: string; url: string }[] = [];
+
+async function main() {
+ Papa.parse(fs.createReadStream("links_com_domain.csv", "utf-8"), {
+ header: true,
+ skipEmptyLines: true,
+ step: (result: { data: { Link: string } }) => {
+ links.push({
+ domain,
+ url: result.data.Link,
+ });
+ },
+ complete: async () => {
+ await redis.lpush(`import:csv:${projectId}`, ...links);
+
+ await qstash.publishJSON({
+ url: `https://app.dub.co/api/cron/import/csv`,
+ body: {
+ projectId,
+ userId,
+ domain,
+ },
+ });
+ },
+ });
+}
+
+main();
diff --git a/apps/web/scripts/download-links.ts b/apps/web/scripts/download-links.ts
new file mode 100644
index 0000000000..a61e9c272b
--- /dev/null
+++ b/apps/web/scripts/download-links.ts
@@ -0,0 +1,28 @@
+import "dotenv-flow/config";
+import prisma from "@/lib/prisma";
+import * as Papa from "papaparse";
+import * as fs from "fs";
+
+const projectId = "xxx";
+
+async function main() {
+ const links = await prisma.link.findMany({
+ where: {
+ projectId,
+ },
+ select: {
+ key: true,
+ domain: true,
+ url: true,
+ },
+ });
+
+ const processedLinks = links.map(({ key, domain, url }) => ({
+ link: `${domain}:${key}`,
+ url,
+ }));
+
+ fs.writeFileSync("links.csv", Papa.unparse(processedLinks));
+}
+
+main();
diff --git a/apps/web/scripts/run.ts b/apps/web/scripts/run.ts
index 5e076bedee..06f285c37c 100644
--- a/apps/web/scripts/run.ts
+++ b/apps/web/scripts/run.ts
@@ -13,7 +13,7 @@ const scriptPath = `./scripts/${command}.${
}`;
exec(
- `tsx ${scriptPath}`,
+ `tsx --stack-size=5120000 ${scriptPath}`,
{ maxBuffer: 1024 * 5000 },
(error, stdout, stderr) => {
if (error) {
diff --git a/apps/web/ui/links/links-container.tsx b/apps/web/ui/links/links-container.tsx
index 81ac281169..877434b939 100644
--- a/apps/web/ui/links/links-container.tsx
+++ b/apps/web/ui/links/links-container.tsx
@@ -10,6 +10,7 @@ import LinkPagination from "./link-pagination";
import LinkSort from "./link-sort";
import NoLinksPlaceholder from "./no-links-placeholder";
import { Suspense } from "react";
+import useLinksCount from "@/lib/swr/use-links-count";
export default function LinksContainer({
AddEditLinkButton,
@@ -17,6 +18,7 @@ export default function LinksContainer({
AddEditLinkButton: () => JSX.Element;
}) {
const { links, isValidating } = useLinks();
+ const { data: count } = useLinksCount();
const { LinkFiltersButton, LinkFiltersModal } = useLinkFiltersModal();
return (
@@ -53,7 +55,7 @@ export default function LinksContainer({
))
)}
</ul>
- {links && links.length > 0 && (
+ {count && count > 0 && (
<Suspense>
<LinkPagination />
</Suspense>