Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

Optimize plugin update check (#1466)

neo7736fb733928f04
diff --git a/screenpipe-app-tauri/components/pipe-store.tsx b/screenpipe-app-tauri/components/pipe-store.tsx
index 79ab05d9f..8bb1fc89e 100644
--- a/screenpipe-app-tauri/components/pipe-store.tsx
+++ b/screenpipe-app-tauri/components/pipe-store.tsx
@@ -922,15 +922,27 @@ export const PipeStore: React.FC = () => {
// Store current time as last check
await localforage.setItem("lastUpdateCheck", now);
- const installedPipes = pipes.filter((pipe) => pipe.is_installed);
+ const installedPipes = pipes.filter((pipe) =>
+ pipe.is_installed &&
+ pipe.installed_config?.version
+ );
+
+ // Skip if no pipes to check
+ if (installedPipes.length === 0) return;
+
+ // Format pipes for batch update check
+ const pluginsToCheck = installedPipes.map(pipe => ({
+ pipe_id: pipe.id,
+ version: pipe.installed_config!.version!
+ }));
const storeApi = await PipeApi.create(settings.user.token);
+ const updates = await storeApi.checkUpdates(pluginsToCheck);
+
+ // Process updates and install them
for (const pipe of installedPipes) {
- const update = await storeApi.checkUpdate(
- pipe.id,
- pipe.installed_config?.version!
- );
- if (update.has_update) {
+ const update = updates.results.find(u => u.pipe_id === pipe.id);
+ if (update && 'has_update' in update && update.has_update) {
await handleUpdatePipe(pipe);
}
}
diff --git a/screenpipe-app-tauri/lib/api/store/index.ts b/screenpipe-app-tauri/lib/api/store/index.ts
index 90fa7229b..beb7dc13a 100644
--- a/screenpipe-app-tauri/lib/api/store/index.ts
+++ b/screenpipe-app-tauri/lib/api/store/index.ts
@@ -61,6 +61,31 @@ export interface CheckUpdateResponse {
latest_file_size: number;
}
+export interface CheckUpdatesRequest {
+ plugins: Array<{
+ pipe_id: string;
+ version: string;
+ }>;
+}
+
+export interface CheckUpdatesResponse {
+ results: Array<
+ | {
+ pipe_id: string;
+ has_update: boolean;
+ current_version: string;
+ latest_version: string;
+ latest_file_hash: string;
+ latest_file_size: number;
+ }
+ | {
+ pipe_id: string;
+ error: string;
+ status: number;
+ }
+ >;
+}
+
interface CacheEntry<T> {
data: T;
timestamp: number;
@@ -251,6 +276,40 @@ export class PipeApi {
}
}
+ async checkUpdates(
+ plugins: Array<{ pipe_id: string; version: string }>
+ ): Promise<CheckUpdatesResponse> {
+ // Create a cache key based on all plugin IDs and versions
+ const cacheKey = `updates_${plugins
+ .map((p) => `${p.pipe_id}_${p.version}`)
+ .join("_")}`;
+ const cached = await this.getCached<CheckUpdatesResponse>(cacheKey);
+ if (cached) return cached;
+
+ try {
+ const response = await fetch(`${this.baseUrl}/api/plugins/check-updates`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${this.authToken}`,
+ },
+ body: JSON.stringify({ plugins }),
+ });
+
+ if (!response.ok) {
+ const { error } = await response.json();
+ throw new Error(`failed to check for updates: ${error}`);
+ }
+
+ const data = await response.json();
+ await this.setCache(cacheKey, data);
+ return data;
+ } catch (error) {
+ console.error("error checking for updates:", error);
+ throw error;
+ }
+ }
+
// method to force refresh cache if needed
async clearCache() {
const keys = await localforage.keys();