forked from mei23/misskey-v11
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 全sharedInbox配信の最適化 * streaming * Tune Co-authored-by: まっちゃとーにゅ <17376330+u1-liquid@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
99 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { SelectQueryBuilder } from 'typeorm'; | ||
import { ReadStream } from 'typeorm/platform/PlatformTools'; | ||
|
||
export async function processStreamingRows<T> (query: SelectQueryBuilder<T>, callback: (row: Record<string, unknown>) => Promise<void>) { | ||
return new Promise(async (res, rej) => { | ||
// query and get stream | ||
let stream: ReadStream; | ||
try { | ||
stream = await query.stream(); | ||
} catch (e) { | ||
return rej(e); | ||
} | ||
|
||
stream | ||
.on('data', async (data: any) => { // Buffer | string のはずだけどobjectが返ってくる | ||
try { | ||
await callback(data); | ||
} catch (e) { | ||
rej(e); | ||
} | ||
}) | ||
.on('end', () => res('end')) | ||
.on('error', err => rej(err)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters