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: improve delete orphan chunks when delete files #4179

Merged
merged 2 commits into from
Sep 28, 2024

Conversation

arvinxx
Copy link
Contributor

@arvinxx arvinxx commented Sep 27, 2024

๐Ÿ’ป ๅ˜ๆ›ด็ฑปๅž‹ | Change Type

  • โœจ feat
  • ๐Ÿ› fix
  • โ™ป๏ธ refactor
  • ๐Ÿ’„ style
  • ๐Ÿ‘ท build
  • โšก๏ธ perf
  • ๐Ÿ“ docs
  • ๐Ÿ”จ chore

๐Ÿ”€ ๅ˜ๆ›ด่ฏดๆ˜Ž | Description of Change

๐Ÿ“ ่กฅๅ……ไฟกๆฏ | Additional Information

ๅœจ LobeChat Cloud ๅฎž้™…็”Ÿไบงไธญ้‡ๅˆฐไธ€ไธชๅฅ‡ๆ€ช็š„ bug๏ผŒ็„ถๅŽๆœ‰ไธคไธช็”จๆˆทๆๆฅๅ้ฆˆ๏ผš

image

ๅ…ทไฝ“ๆŠ›้”™ๅฆ‚ไธ‹๏ผš

RangeError: Maximum call stack size exceeded
    at /var/task/.next/server/chunks/59261.js:22:22558
    ... 8 lines matching cause stack trace ...
    at Object.startActiveSpan (/var/task/.next/server/chunks/59261.js:22:28365) {
  code: 'INTERNAL_SERVER_ERROR',
  name: 'TRPCError',
  [cause]: RangeError: Maximum call stack size exceeded
      at /var/task/.next/server/chunks/59261.js:22:22558
      at m.buildQueryFromSourceParams (/var/task/.next/server/chunks/59261.js:22:22661)
      at /var/task/.next/server/chunks/59261.js:22:23020
      at Array.map (<anonymous>)
      at m.buildQueryFromSourceParams (/var/task/.next/server/chunks/59261.js:22:22664)
      at /var/task/.next/server/chunks/59261.js:22:23020
      at Array.map (<anonymous>)
      at m.buildQueryFromSourceParams (/var/task/.next/server/chunks/59261.js:22:22664)
      at /var/task/.next/server/chunks/59261.js:22:22086
      at Object.startActiveSpan (/var/task/.next/server/chunks/59261.js:22:28365)
}

้ฆ–ๅ…ˆๅœจ src ไธ‹ๆœไบ†ไธ‹ไธๅญ˜ๅœจ buildQueryFromSourceParams ่ฟ™ไธช่ฐƒ็”จ๏ผŒๅ› ๆญคๆŠ›้”™ๅค„ไธๆ˜ฏๆบ็ ้ƒจๅˆ†ใ€‚็„ถๅŽๆ‹ฟ่ฟ™ไธชๆœไบ†ไธ‹ๅ‘็Žฐๆ˜ฏ Drizzle ็š„่ฐƒ็”จๅฎž็Žฐ๏ผŒไนŸๆœ‰ไธ€ไธชไธ€ๆจกไธ€ๆ ท็š„ issue:

ๆ‰พๆŠ›้”™็š„ไฝ็ฝฎๆ‰พๅˆฐไบ†่ฟ™ไธ€้ƒจๅˆ†๏ผš

deleteOrphanChunks = async () => {
    const orphanedChunks = await serverDB
      .select({ chunkId: chunks.id })
      .from(chunks)
      .leftJoin(fileChunks, eq(chunks.id, fileChunks.chunkId))
      .where(isNull(fileChunks.fileId));
    const ids = orphanedChunks.map((chunk) => chunk.chunkId);
    if (ids.length === 0) return;

    await serverDB.delete(chunks).where(inArray(chunks.id, ids));
  };

ๅฎƒ็š„้—ฎ้ข˜ๅฐฑๅ‡บๅœจๅฆ‚ๆžœ chunkIds ็š„ๆ€ปๆ•ฐ่ฟ‡ๅคš๏ผŒ้‚ฃไนˆ inArray(chunks.id, chunkIds) ่ฟ™ๆ ท็š„ๅ†™ๆณ•ๅฐฑไผšๅ‡บ็Žฐๅ †ๆ ˆๆบขๅ‡บ็š„ๆƒ…ๅ†ตใ€‚

่€Œๅœจ Neon ๆŽงๅˆถๅฐๅ†™ไบ†ๆฎต SQL ๆŸฅ่ฏข๏ผŒๅ‘็Žฐ orphanedChunks ๅฑ…็„ถๆœ‰ 161k ไน‹ๅคšโ€ฆ ่ฟ™ๆ‰ๅฏผ่‡ด็บฟไธŠๅˆ ๆ–‡ไปถๆ—ถๆ— ๆณ•ๆญฃๅธธๅˆ ้™คใ€‚

ๅ› ๆญคๅฐ่ฏ•ๅฐ† inArrary ็š„ๅฎž็Žฐไผ˜ๅŒ–ไธบๅนณ่กŒๅˆ†ๆ‰นๅˆ ้™ค๏ผŒๆœŸๆœ›ไผ˜ๅŒ–่ฏฅๆ•ˆๆžœ่ƒฝ่งฃๅ†ณ่ฟ‡ๅคš็š„้—ฎ้ข˜

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Sep 27, 2024
Copy link

vercel bot commented Sep 27, 2024

The latest updates on your projects. Learn more about Vercel for Git โ†—๏ธŽ

Name Status Preview Updated (UTC)
lobe-chat-preview โœ… Ready (Inspect) Visit Preview Sep 27, 2024 5:20pm

@lobehubbot
Copy link
Member

๐Ÿ‘ @arvinxx

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
้žๅธธๆ„Ÿ่ฐขๆ‚จๆๅ‡บๆ‹‰ๅ–่ฏทๆฑ‚ๅนถไธบๆˆ‘ไปฌ็š„็คพๅŒบๅšๅ‡บ่ดก็Œฎ๏ผŒ่ฏท็กฎไฟๆ‚จๅทฒ็ป้ตๅพชไบ†ๆˆ‘ไปฌ็š„่ดก็ŒฎๆŒ‡ๅ—๏ผŒๆˆ‘ไปฌไผšๅฐฝๅฟซๅฎกๆŸฅๅฎƒใ€‚
ๅฆ‚ๆžœๆ‚จ้‡ๅˆฐไปปไฝ•้—ฎ้ข˜๏ผŒ่ฏท้šๆ—ถไธŽๆˆ‘ไปฌ่”็ณปใ€‚

@dosubot dosubot bot added the ๐Ÿ› Bug Something isn't working | ็ผบ้™ท label Sep 27, 2024
Copy link

codecov bot commented Sep 27, 2024

Codecov Report

All modified and coverable lines are covered by tests โœ…

Project coverage is 92.51%. Comparing base (b0c3abc) to head (81626cf).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4179   +/-   ##
=======================================
  Coverage   92.50%   92.51%           
=======================================
  Files         484      484           
  Lines       34748    34757    +9     
  Branches     2143     2145    +2     
=======================================
+ Hits        32145    32154    +9     
  Misses       2603     2603           
Flag Coverage ฮ”
app 92.51% <100.00%> (+<0.01%) โฌ†๏ธ
server 97.37% <100.00%> (+<0.01%) โฌ†๏ธ

Flags with carried forward coverage won't be shown. Click here to find out more.

โ˜” View full report in Codecov by Sentry.
๐Ÿ“ข Have feedback on the report? Share it here.

@arvinxx arvinxx changed the title ๐Ÿ› fix: improve delete orphan chunks implement ๐Ÿ› fix: improve delete orphan chunks when delete files Sep 27, 2024
@arvinxx arvinxx merged commit f3e0ffe into main Sep 28, 2024
14 checks passed
@arvinxx arvinxx deleted the fix/delete-chunks branch September 28, 2024 15:00
@lobehubbot
Copy link
Member

โค๏ธ Great PR @arvinxx โค๏ธ

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.
้กน็›ฎ็š„ๆˆ้•ฟ็ฆปไธๅผ€็”จๆˆทๅ้ฆˆๅ’Œ่ดก็Œฎ๏ผŒๆ„Ÿ่ฐขๆ‚จ็š„่ดก็Œฎ! ๅฆ‚ๆžœๆ‚จๅฏน LobeHub ๅผ€ๅ‘่€…็คพๅŒบๆ„Ÿๅ…ด่ถฃ๏ผŒ่ฏทๅŠ ๅ…ฅๆˆ‘ไปฌ็š„ discord๏ผŒ็„ถๅŽ็งไฟก @arvinxx ๆˆ– @canisminor1990ใ€‚ไป–ไปฌไผš้‚€่ฏทๆ‚จๅŠ ๅ…ฅๆˆ‘ไปฌ็š„็งๅฏ†ๅผ€ๅ‘่€…้ข‘้“ใ€‚ๆˆ‘ไปฌๅฐ†ไผš่ฎจ่ฎบๅ…ณไบŽ Lobe Chat ็š„ๅผ€ๅ‘๏ผŒๅˆ†ไบซๅ’Œ่ฎจ่ฎบๅ…จ็ƒ่Œƒๅ›ดๅ†…็š„ AI ๆถˆๆฏใ€‚

github-actions bot pushed a commit that referenced this pull request Sep 28, 2024
### [Version&nbsp;1.20.3](v1.20.2...v1.20.3)
<sup>Released on **2024-09-28**</sup>

#### ๐Ÿ› Bug Fixes

- **misc**: Improve delete orphan chunks when delete files.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

* **misc**: Improve delete orphan chunks when delete files, closes [#4179](#4179) ([f3e0ffe](f3e0ffe))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Member

๐ŸŽ‰ This PR is included in version 1.20.3 ๐ŸŽ‰

The release is available on:

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

github-actions bot pushed a commit to bentwnghk/lobe-chat that referenced this pull request Sep 28, 2024
### [Version&nbsp;1.63.2](v1.63.1...v1.63.2)
<sup>Released on **2024-09-28**</sup>

#### ๐Ÿ› Bug Fixes

- **misc**: Improve delete orphan chunks when delete files.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### What's fixed

* **misc**: Improve delete orphan chunks when delete files, closes [lobehub#4179](https://github.com/bentwnghk/lobe-chat/issues/4179) ([f3e0ffe](f3e0ffe))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
cookieY added a commit to cookieY/lobe-chat that referenced this pull request Sep 29, 2024
* 'main' of github.com:cookieY/lobe-chat:
  ๐Ÿ”– chore(release): v1.20.5 [skip ci]
  ๐Ÿ“ docs: Update docker-compose to use new LOGTO env (lobehub#4199)
  ๐Ÿ‘ท build: optimize image size under glibc env (lobehub#4176)
  ๐Ÿ”– chore(release): v1.20.4 [skip ci]
  โšก perf: remove some blur style to improve performance (lobehub#4085)
  Update dependency unstructured-client to ^0.18.0 (lobehub#4065)
  ๐Ÿ“ docs: Add deployment using ZITADEL authentication services (lobehub#4081)
  ๐Ÿ”– chore(release): v1.20.3 [skip ci]
  ๐Ÿ› fix: improve delete orphan chunks when delete files (lobehub#4179)
  ๐Ÿ“ docs: add new configuration item of clerk singup (lobehub#4188)
  ๐Ÿ“ docs: update model-provider document (lobehub#4181)
  ๐Ÿ”– chore(release): v1.20.2 [skip ci]
  ๐Ÿ’„ style: add zhipu glm-4-flashx model (lobehub#4173)
  ๐Ÿ‘ท build: revert lobehub#4025 (lobehub#4175)
  ๐Ÿ”– chore(release): v1.20.1 [skip ci]
  ๐Ÿ‘ท build: optimize image size under `glibc` env (lobehub#4025)
  ๐Ÿ”– chore(release): v1.20.0 [skip ci]
  โœจ feat: add Hunyuan(Tencent) model provider (lobehub#4147)
  ๐Ÿ”– chore(release): v1.19.36 [skip ci]
  ๐Ÿ’„ style: add llama3.2 model for openrouter provider (lobehub#4151)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
๐Ÿ› Bug Something isn't working | ็ผบ้™ท released size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants