Changesets · Branches · Tags · Compare
| Changeset | a4e52f074c3846c6d0e25181e844c8e881b2cb4f659c3bd321ceab0930f4003c |
|---|---|
| Author | Dallin Romney <dallinromney@gmail.com> · 2025-07-11 00:07 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-11 00:07 -07:00 |
| Parents | 275abb44c5e4, d667427437b4 |
8 files changed
modified core/core.ts +0 −6
| @@ -11,7 +11,6 @@ | ||
| 11 | 11 | import { SYSTEM_PROMPT_DOT_FILE } from "./config/getWorkspaceContinueRuleDotFiles"; |
| 12 | 12 | import { addModel, deleteModel } from "./config/util"; |
| 13 | 13 | import CurrentFileContextProvider from "./context/providers/CurrentFileContextProvider"; |
| 14 | -import { ContinueServerClient } from "./continueServer/stubs/client"; | |
| 15 | 14 | import { getAuthUrlForTokenPage } from "./control-plane/auth/index"; |
| 16 | 15 | import { getControlPlaneEnv } from "./control-plane/env"; |
| 17 | 16 | import { DevDataSqliteDb } from "./data/devdataSqlite"; |
| @@ -202,11 +201,6 @@ | ||
| 202 | 201 | dataLogger.ideSettingsPromise = ideSettingsPromise; |
| 203 | 202 | |
| 204 | 203 | void ideSettingsPromise.then((ideSettings) => { |
| 205 | - const continueServerClient = new ContinueServerClient( | |
| 206 | - ideSettings.remoteConfigServerUrl, | |
| 207 | - ideSettings.userToken, | |
| 208 | - ); | |
| 209 | - | |
| 210 | 204 | // Index on initialization |
| 211 | 205 | void this.ide.getWorkspaceDirs().then(async (dirs) => { |
| 212 | 206 | // Respect pauseCodebaseIndexOnStart user settings |
modified core/index.d.ts +1 −0
| @@ -50,6 +50,7 @@ | ||
| 50 | 50 | shouldClearIndexes?: boolean; |
| 51 | 51 | status: |
| 52 | 52 | | "loading" |
| 53 | + | "waiting" | |
| 53 | 54 | | "indexing" |
| 54 | 55 | | "done" |
| 55 | 56 | | "failed" |
modified core/indexing/CodebaseIndexer.ts +40 −1
| @@ -16,7 +16,7 @@ | ||
| 16 | 16 | import { CodeSnippetsCodebaseIndex } from "./CodeSnippetsIndex.js"; |
| 17 | 17 | import { FullTextSearchCodebaseIndex } from "./FullTextSearchCodebaseIndex.js"; |
| 18 | 18 | import { LanceDbIndex } from "./LanceDbIndex.js"; |
| 19 | -import { getComputeDeleteAddRemove } from "./refreshIndex.js"; | |
| 19 | +import { getComputeDeleteAddRemove, IndexLock } from "./refreshIndex.js"; | |
| 20 | 20 | import { |
| 21 | 21 | CodebaseIndex, |
| 22 | 22 | IndexResultType, |
| @@ -643,11 +643,47 @@ | ||
| 643 | 643 | ); |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | + /** | |
| 647 | + * We want to prevent sqlite concurrent write errors | |
| 648 | + * when there are 2 indexing happening from different windows. | |
| 649 | + * We want the other window to wait until the first window's indexing finishes. | |
| 650 | + * Incase the first window closes before indexing is finished, | |
| 651 | + * we want to unlock the IndexLock by checking the last timestamp. | |
| 652 | + */ | |
| 653 | + private async *waitForDBIndex(): AsyncGenerator<IndexingProgressUpdate> { | |
| 654 | + let foundLock = await IndexLock.isLocked(); | |
| 655 | + while (foundLock?.locked) { | |
| 656 | + if ((Date.now() - foundLock.timestamp) / 1000 > 10) { | |
| 657 | + console.log(`${foundLock.dirs} is not being indexed... unlocking`); | |
| 658 | + await IndexLock.unlock(); | |
| 659 | + break; | |
| 660 | + } | |
| 661 | + console.log(`indexing ${foundLock.dirs}`); | |
| 662 | + yield { | |
| 663 | + progress: 0, | |
| 664 | + desc: "", | |
| 665 | + status: "waiting", | |
| 666 | + }; | |
| 667 | + await new Promise((resolve) => setTimeout(resolve, 1000)); | |
| 668 | + foundLock = await IndexLock.isLocked(); | |
| 669 | + } | |
| 670 | + } | |
| 671 | + | |
| 646 | 672 | public async refreshCodebaseIndex(paths: string[]) { |
| 647 | 673 | if (this.indexingCancellationController) { |
| 648 | 674 | this.indexingCancellationController.abort(); |
| 649 | 675 | } |
| 650 | 676 | this.indexingCancellationController = new AbortController(); |
| 677 | + for await (const update of this.waitForDBIndex()) { | |
| 678 | + this.updateProgress(update); | |
| 679 | + } | |
| 680 | + | |
| 681 | + await IndexLock.lock(paths.join(", ")); // acquire the index lock to prevent multiple windows to begin indexing | |
| 682 | + const indexLockTimestampUpdateInterval = setInterval( | |
| 683 | + () => void IndexLock.updateTimestamp(), | |
| 684 | + 5_000, | |
| 685 | + ); | |
| 686 | + | |
| 651 | 687 | try { |
| 652 | 688 | for await (const update of this.refreshDirs( |
| 653 | 689 | paths, |
| @@ -664,6 +700,9 @@ | ||
| 664 | 700 | await this.handleIndexingError(e); |
| 665 | 701 | } |
| 666 | 702 | |
| 703 | + clearInterval(indexLockTimestampUpdateInterval); // interval will also be cleared when window closes before indexing is finished | |
| 704 | + await IndexLock.unlock(); | |
| 705 | + | |
| 667 | 706 | // Directly refresh submenu items |
| 668 | 707 | if (this.messenger) { |
| 669 | 708 | this.messenger.send("refreshSubmenuItems", { |
modified core/indexing/refreshIndex.ts +54 −0
| @@ -45,6 +45,16 @@ | ||
| 45 | 45 | artifactId STRING NOT NULL |
| 46 | 46 | )`, |
| 47 | 47 | ); |
| 48 | + | |
| 49 | + await db.exec( | |
| 50 | + `CREATE TABLE IF NOT EXISTS indexing_lock ( | |
| 51 | + id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| 52 | + locked BOOLEAN NOT NULL, | |
| 53 | + timestamp INTEGER NOT NULL, | |
| 54 | + dirs STRING NOT NULL | |
| 55 | + )`, | |
| 56 | + ); | |
| 57 | + | |
| 48 | 58 | // Delete duplicate rows from tag_catalog |
| 49 | 59 | await db.exec(` |
| 50 | 60 | DELETE FROM tag_catalog |
| @@ -532,3 +542,47 @@ | ||
| 532 | 542 | export function truncateSqliteLikePattern(input: string, safety: number = 100) { |
| 533 | 543 | return truncateToLastNBytes(input, SQLITE_MAX_LIKE_PATTERN_LENGTH - safety); |
| 534 | 544 | } |
| 545 | + | |
| 546 | +export class IndexLock { | |
| 547 | + private static getLockTableName() { | |
| 548 | + return "indexing_lock"; | |
| 549 | + } | |
| 550 | + | |
| 551 | + static async isLocked(): Promise< | |
| 552 | + { locked: boolean; dirs: string; timestamp: number } | undefined | undefined | |
| 553 | + > { | |
| 554 | + const db = await SqliteDb.get(); | |
| 555 | + const row = (await db.get( | |
| 556 | + `SELECT locked, dirs, timestamp FROM ${IndexLock.getLockTableName()} WHERE locked = ?`, | |
| 557 | + true, | |
| 558 | + )) as { locked: boolean; dirs: string; timestamp: number } | undefined; | |
| 559 | + return row; | |
| 560 | + } | |
| 561 | + | |
| 562 | + static async lock(dirs: string) { | |
| 563 | + const db = await SqliteDb.get(); | |
| 564 | + await db.run( | |
| 565 | + `INSERT INTO ${IndexLock.getLockTableName()} (locked, timestamp, dirs) VALUES (?, ?, ?)`, | |
| 566 | + true, | |
| 567 | + Date.now(), | |
| 568 | + dirs, | |
| 569 | + ); | |
| 570 | + } | |
| 571 | + | |
| 572 | + static async updateTimestamp() { | |
| 573 | + const db = await SqliteDb.get(); | |
| 574 | + await db.run( | |
| 575 | + `UPDATE ${IndexLock.getLockTableName()} SET timestamp = ? where locked = ?`, | |
| 576 | + Date.now(), | |
| 577 | + true, | |
| 578 | + ); | |
| 579 | + } | |
| 580 | + | |
| 581 | + static async unlock() { | |
| 582 | + const db = await SqliteDb.get(); | |
| 583 | + await db.run( | |
| 584 | + `DELETE FROM ${IndexLock.getLockTableName()} WHERE locked = ?`, | |
| 585 | + true, | |
| 586 | + ); | |
| 587 | + } | |
| 588 | +} |
modified gui/src/pages/config/IndexingProgress/IndexingProgress.tsx +1 −1
| @@ -111,7 +111,7 @@ | ||
| 111 | 111 | <div className="mt-4 flex flex-col"> |
| 112 | 112 | <div className="mb-0 flex justify-between text-sm"> |
| 113 | 113 | <IndexingProgressTitleText update={update} /> |
| 114 | - {update.status !== "loading" && ( | |
| 114 | + {!["loading", "waiting"].includes(update.status) && ( | |
| 115 | 115 | <IndexingProgressIndicator update={update} /> |
| 116 | 116 | )} |
| 117 | 117 | </div> |
modified gui/src/pages/config/IndexingProgress/IndexingProgressIndicator.tsx +1 −0
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | const STATUS_TO_ICON: Record<IndexingProgressUpdate["status"], any> = { |
| 14 | 14 | disabled: null, |
| 15 | 15 | loading: null, |
| 16 | + waiting: null, | |
| 16 | 17 | indexing: ArrowPathIcon, |
| 17 | 18 | paused: PauseCircleIcon, |
| 18 | 19 | done: CheckCircleIcon, |
modified gui/src/pages/config/IndexingProgress/IndexingProgressSubtext.tsx +1 −0
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | > = { |
| 12 | 12 | done: "Click to re-index", |
| 13 | 13 | loading: "", |
| 14 | + waiting: "", | |
| 14 | 15 | indexing: "Click to pause", |
| 15 | 16 | paused: "Click to resume", |
| 16 | 17 | failed: "Click to retry", |
modified gui/src/pages/config/IndexingProgress/IndexingProgressTitleText.tsx +1 −0
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | const STATUS_TO_TEXT: Record<IndexingProgressUpdate["status"], string> = { |
| 9 | 9 | done: "Indexing complete", |
| 10 | 10 | loading: "Initializing", |
| 11 | + waiting: "Indexing other workspace", | |
| 11 | 12 | indexing: "Indexing in-progress", |
| 12 | 13 | paused: "Indexing paused", |
| 13 | 14 | failed: "Indexing failed", |