This repository was archived by the owner on Mar 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -125,11 +125,25 @@ export class ScannerChannel implements IpcChannelInterface {
125125 } as Song
126126 }
127127
128+ private async saveToDb ( songs : Song [ ] ) {
129+ await getSongDB ( ) . store ( ...songs )
130+ }
131+
132+ private songList : Song [ ] = new Proxy < Song [ ] > ( [ ] , {
133+ set : ( target , property , value ) => {
134+ target [ property as unknown as number ] = value
135+ if ( target . length >= 50 ) {
136+ this . saveToDb ( target . splice ( 0 , target . length ) )
137+ }
138+ return true
139+ }
140+ } )
141+
128142 private async storeSong ( data : SongWithLen ) {
129143 this . totalScanFiles = data . size
130144 this . reportProgress ( data . current )
131145
132- await getSongDB ( ) . store ( this . parseScannedSong ( data . song ) )
146+ this . songList . push ( this . parseScannedSong ( data . song ) )
133147 }
134148
135149 private parseScannedPlaylist ( data : ScanPlaylist ) : Playlist {
@@ -181,7 +195,12 @@ export class ScannerChannel implements IpcChannelInterface {
181195 }
182196 }
183197 } ,
184- ( ) => Promise . allSettled ( promises ) . then ( ( ) => resolve ( lastValue ) )
198+ ( ) =>
199+ Promise . allSettled ( promises ) . then ( ( ) => {
200+ if ( store ) this . saveToDb ( this . songList )
201+ this . songList = [ ]
202+ return resolve ( lastValue )
203+ } )
185204 )
186205 } )
187206 }
You can’t perform that action at this time.
0 commit comments