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

fix(orama): remove INTERNAL packages from index, and chunk reindexing #742

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions api/src/orama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ impl OramaClient {

#[instrument(name = "OramaClient::upsert_package", skip(self))]
pub fn upsert_package(&self, package: &Package, meta: &PackageVersionMeta) {
if package.version_count == 0
|| package.is_archived
|| package.description.starts_with("INTERNAL")
{
if package.version_count == 0 || package.is_archived {
return;
}

if package.description.starts_with("INTERNAL") {
self.delete_package(&package.scope, &package.name);
return;
}

let id = format!("@{}/{}", package.scope, package.name);
let score = package
.latest_version
Expand Down
25 changes: 14 additions & 11 deletions tools/orama_package_reindex.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
import type { List, Package } from "../frontend/utils/api_types.ts";
import type { OramaPackageHit } from "../frontend/util.ts";
import { chunk } from "jsr:@std/collections";

const index = Deno.env.get("ORAMA_PACKAGE_INDEX_ID");
const auth = Deno.env.get("ORAMA_PACKAGE_PRIVATE_API_KEY");
Expand Down Expand Up @@ -54,17 +55,19 @@ const entries: OramaPackageHit[] = packages
id: `@${entry.scope}/${entry.name}`,
}));

const res2 = await fetch(`${ORAMA_URL}/${index}/notify`, {
method: "POST",
headers: {
authorization: `Bearer ${auth}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ "upsert": entries }),
});
if (res2.status !== 200) {
console.log(await res2.text());
throw res2;
for (const entriesChunk of chunk(entries, 1000)) {
const res2 = await fetch(`${ORAMA_URL}/${index}/notify`, {
method: "POST",
headers: {
authorization: `Bearer ${auth}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ "upsert": entriesChunk }),
});
if (res2.status !== 200) {
console.log(await res2.text());
throw res2;
}
}

// deploy the index
Expand Down
Loading