mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix: Use D1 for indices (#11199)
* fix: use D1 for indices * fix: use D1 for indices * build: remove unused packages * fix: pass variables --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
4
.github/workflows/documentation.yml
vendored
4
.github/workflows/documentation.yml
vendored
@@ -277,7 +277,9 @@ jobs:
|
|||||||
|
|
||||||
- name: Upload search indices to meilisearch
|
- name: Upload search indices to meilisearch
|
||||||
env:
|
env:
|
||||||
DATABASE_URL: ${{ secrets.DATABASE_URL }}
|
CF_D1_DOCS_API_KEY: ${{ secrets.CF_D1_DOCS_API_KEY }}
|
||||||
|
CF_D1_DOCS_ID: ${{ secrets.CF_D1_DOCS_ID }}
|
||||||
|
CF_ACCOUNT_ID: ${{ secrets.CF_ACCOUNT_ID }}
|
||||||
SEARCH_API_URL: ${{ secrets.SEARCH_API_URL }}
|
SEARCH_API_URL: ${{ secrets.SEARCH_API_URL }}
|
||||||
SEARCH_API_KEY: ${{ secrets.SEARCH_API_KEY }}
|
SEARCH_API_KEY: ${{ secrets.SEARCH_API_KEY }}
|
||||||
uses: ./packages/actions/src/uploadSearchIndices
|
uses: ./packages/actions/src/uploadSearchIndices
|
||||||
|
|||||||
@@ -46,8 +46,6 @@
|
|||||||
"@actions/glob": "^0.5.0",
|
"@actions/glob": "^0.5.0",
|
||||||
"@aws-sdk/client-s3": "^3.901.0",
|
"@aws-sdk/client-s3": "^3.901.0",
|
||||||
"@discordjs/scripts": "workspace:^",
|
"@discordjs/scripts": "workspace:^",
|
||||||
"@vercel/blob": "^2.0.0",
|
|
||||||
"@vercel/postgres": "^0.10.0",
|
|
||||||
"cloudflare": "^5.2.0",
|
"cloudflare": "^5.2.0",
|
||||||
"commander": "^14.0.1",
|
"commander": "^14.0.1",
|
||||||
"meilisearch": "^0.38.0",
|
"meilisearch": "^0.38.0",
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
import { setFailed } from '@actions/core';
|
import { setFailed } from '@actions/core';
|
||||||
import { generateAllIndices } from '@discordjs/scripts';
|
import { generateAllIndices } from '@discordjs/scripts';
|
||||||
import { createPool } from '@vercel/postgres';
|
import Cloudflare from 'cloudflare';
|
||||||
import { MeiliSearch } from 'meilisearch';
|
import { MeiliSearch } from 'meilisearch';
|
||||||
import pLimit from 'p-limit';
|
import pLimit from 'p-limit';
|
||||||
import { fetch } from 'undici';
|
import { fetch } from 'undici';
|
||||||
|
|
||||||
if (!process.env.DATABASE_URL) {
|
if (!(process.env.CF_D1_DOCS_API_KEY && process.env.CF_D1_DOCS_ID && process.env.CF_ACCOUNT_ID)) {
|
||||||
setFailed('DATABASE_URL is not set');
|
setFailed('Missing Cloudflare D1 environment variables.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!process.env.SEARCH_API_URL) {
|
if (!process.env.SEARCH_API_URL) {
|
||||||
@@ -18,8 +18,8 @@ if (!process.env.SEARCH_API_KEY) {
|
|||||||
setFailed('SEARCH_API_KEY is not set');
|
setFailed('SEARCH_API_KEY is not set');
|
||||||
}
|
}
|
||||||
|
|
||||||
const pool = createPool({
|
const cf = new Cloudflare({
|
||||||
connectionString: process.env.DATABASE_URL,
|
apiToken: process.env.CF_D1_DOCS_API_KEY!,
|
||||||
});
|
});
|
||||||
|
|
||||||
const client = new MeiliSearch({
|
const client = new MeiliSearch({
|
||||||
@@ -34,16 +34,26 @@ try {
|
|||||||
console.log('Generating all indices...');
|
console.log('Generating all indices...');
|
||||||
const indices = await generateAllIndices({
|
const indices = await generateAllIndices({
|
||||||
fetchPackageVersions: async (pkg) => {
|
fetchPackageVersions: async (pkg) => {
|
||||||
console.log(`Fetching versions for ${pkg}...`);
|
console.info(`Fetching versions for ${pkg}...`);
|
||||||
const { rows } = await pool.sql`select version from documentation where name = ${pkg}`;
|
|
||||||
|
|
||||||
return rows.map((row) => row.version);
|
const { result } = await cf.d1.database.query(process.env.CF_D1_DOCS_ID!, {
|
||||||
|
account_id: process.env.CF_ACCOUNT_ID!,
|
||||||
|
sql: `select version from documentation where name = ? order by version desc;`,
|
||||||
|
params: [pkg],
|
||||||
|
});
|
||||||
|
|
||||||
|
return ((result[0]?.results as { version: string }[] | undefined) ?? []).map((row) => row.version);
|
||||||
},
|
},
|
||||||
fetchPackageVersionDocs: async (pkg, version) => {
|
fetchPackageVersionDocs: async (pkg, version) => {
|
||||||
console.log(`Fetching data for ${pkg} ${version}...`);
|
console.log(`Fetching data for ${pkg} ${version}...`);
|
||||||
const { rows } = await pool.sql`select url from documentation where name = ${pkg} and version = ${version}`;
|
|
||||||
const res = await fetch(rows[0]?.url ?? '');
|
|
||||||
|
|
||||||
|
const { result } = await cf.d1.database.query(process.env.CF_D1_DOCS_ID!, {
|
||||||
|
account_id: process.env.CF_ACCOUNT_ID!,
|
||||||
|
sql: `select url from documentation where name = ? and version = ?;`,
|
||||||
|
params: [pkg, version],
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await fetch(((result[0]?.results as { url: string }[] | undefined) ?? [])[0]?.url ?? '');
|
||||||
return res.json();
|
return res.json();
|
||||||
},
|
},
|
||||||
writeToFile: false,
|
writeToFile: false,
|
||||||
|
|||||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -459,12 +459,6 @@ importers:
|
|||||||
'@discordjs/scripts':
|
'@discordjs/scripts':
|
||||||
specifier: workspace:^
|
specifier: workspace:^
|
||||||
version: link:../scripts
|
version: link:../scripts
|
||||||
'@vercel/blob':
|
|
||||||
specifier: ^2.0.0
|
|
||||||
version: 2.0.0
|
|
||||||
'@vercel/postgres':
|
|
||||||
specifier: ^0.10.0
|
|
||||||
version: 0.10.0
|
|
||||||
cloudflare:
|
cloudflare:
|
||||||
specifier: ^5.2.0
|
specifier: ^5.2.0
|
||||||
version: 5.2.0(encoding@0.1.13)
|
version: 5.2.0(encoding@0.1.13)
|
||||||
|
|||||||
Reference in New Issue
Block a user