From b22066b9a26beffc03ecc499ed861366dfaf4340 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Tue, 24 Oct 2023 06:16:40 +0900 Subject: [PATCH 01/20] =?UTF-8?q?ci:=20fix=20pull=5Freq=E6=99=82=E3=81=ABA?= =?UTF-8?q?PI=20diff=E3=81=AE=E5=AE=9F=E8=A1=8C=E3=81=8C=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=81=AA=E3=81=84=20(#12123)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * initial commit for report-api-diff.yml * add api-{base,head}.json into api-artifact * try to get pull request id from github.event.workflow_run.pull_requests * Update report-api-diff.yml * Update report-api-diff.yml * remove save-pr-number --- .github/workflows/get-api-diff.yml | 56 +--------------- .github/workflows/report-api-diff.yml | 92 +++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/report-api-diff.yml diff --git a/.github/workflows/get-api-diff.yml b/.github/workflows/get-api-diff.yml index 9bab4f6583..6454de080c 100644 --- a/.github/workflows/get-api-diff.yml +++ b/.github/workflows/get-api-diff.yml @@ -1,4 +1,5 @@ -name: Report API Diff +# this name is used in report-api-diff.yml so be careful when change name +name: Get api.json from Misskey on: pull_request: @@ -170,56 +171,3 @@ jobs: path: api-head.json - name: Kill Misskey Job run: screen -S misskey -X quit - - compare-diff: - runs-on: ubuntu-latest - if: success() - needs: [get-base, get-head] - permissions: - pull-requests: write - - steps: - - name: Download Artifact - uses: actions/download-artifact@v3 - with: - name: api-artifact - path: ./artifacts - - name: Output base - run: cat ./artifacts/api-base.json - - name: Output head - run: cat ./artifacts/api-head.json - - name: Arrange json files - run: | - jq '.' ./artifacts/api-base.json > ./api-base.json - jq '.' ./artifacts/api-head.json > ./api-head.json - - name: Get diff of 2 files - run: diff -u --label=base --label=head ./api-base.json ./api-head.json | cat > api.json.diff - - name: Get full diff - run: diff --label=base --label=head --new-line-format='+%L' --old-line-format='-%L' --unchanged-line-format=' %L' ./api-base.json ./api-head.json | cat > api-full.json.diff - - name: Echo full diff - run: cat ./api-full.json.diff - - name: Upload full diff to Artifact - uses: actions/upload-artifact@v3 - with: - name: api-artifact - path: api-full.json.diff - - id: out-diff - name: Build diff Comment - run: | - cat <<- EOF > ./output.md - このPRによるapi.jsonの差分 -
- 差分はこちら - - \`\`\`diff - $(cat ./api.json.diff) - \`\`\` -
- - [Get diff files from Workflow Page](https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}) - EOF - - name: Write diff comment - uses: thollander/actions-comment-pull-request@v2 - with: - comment_tag: show_diff - filePath: ./output.md diff --git a/.github/workflows/report-api-diff.yml b/.github/workflows/report-api-diff.yml new file mode 100644 index 0000000000..9e7f47f923 --- /dev/null +++ b/.github/workflows/report-api-diff.yml @@ -0,0 +1,92 @@ +name: Report API Diff + +on: + workflow_run: + types: [completed] + workflows: + - Get api.json from Misskey # get-api-diff.yml + +jobs: + compare-diff: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} + permissions: + pull-requests: write + +# api-artifact + steps: + - name: Download artifact + uses: actions/github-script@v6 + with: + script: | + let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.payload.workflow_run.id, + }); + let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == "api-artifact" + })[0]; + let download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + let fs = require('fs'); + fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/api-artifact.zip`, Buffer.from(download.data)); + - name: Extract artifact + run: unzip api-artifact.zip -d artifacts + - name: Load PR Number + id: load-pr-num + env: + PULL_REQUESTS: ${{ toJson(github.event.workflow_run.pull_requests.*) }} + REPO_ID: ${{ github.repository_id }} + run: | + # find first pull requests that targets this repository + PR_NUMBER="$(echo "$PULL_REQUESTS" \ + | jq --arg REPO_ID "$REPO_ID" '[.[] | select ($REPO_ID == (.base.repo.id | tostring)) | .number ][0]')" + echo "pr-number=$PR_NUMBER" >> "$GITHUB_OUTPUT" + + - name: Output base + run: cat ./artifacts/api-base.json + - name: Output head + run: cat ./artifacts/api-head.json + - name: Arrange json files + run: | + jq '.' ./artifacts/api-base.json > ./api-base.json + jq '.' ./artifacts/api-head.json > ./api-head.json + - name: Get diff of 2 files + run: diff -u --label=base --label=head ./api-base.json ./api-head.json | cat > api.json.diff + - name: Get full diff + run: diff --label=base --label=head --new-line-format='+%L' --old-line-format='-%L' --unchanged-line-format=' %L' ./api-base.json ./api-head.json | cat > api-full.json.diff + - name: Echo full diff + run: cat ./api-full.json.diff + - name: Upload full diff to Artifact + uses: actions/upload-artifact@v3 + with: + name: api-artifact + path: | + api-full.json.diff + api-base.json + api-head.json + - id: out-diff + name: Build diff Comment + run: | + cat <<- EOF > ./output.md + このPRによるapi.jsonの差分 +
+ 差分はこちら + + \`\`\`diff + $(cat ./api.json.diff) + \`\`\` +
+ + [Get diff files from Workflow Page](https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}) + EOF + - uses: thollander/actions-comment-pull-request@v2 + with: + pr_number: ${{ steps.load-pr-num.outputs.pr-number }} + comment_tag: show_diff + filePath: ./output.md From 7e15f7191631a2f50fabae940a8affe808793aca Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Tue, 24 Oct 2023 14:02:06 +0900 Subject: [PATCH 02/20] ci: fix pullreq number may not get correctly (#12127) * Revert "remove save-pr-number" This reverts commit 085f4bd76992fa0b3e4219a5c132b72f68c3d2cc. * Revert "Update report-api-diff.yml" This reverts commit b73daf4c0ec4240ea39b183a6b93f209b63e6d81. * Revert "Update report-api-diff.yml" This reverts commit cbf2b5ad8a7cba769446fa9bcf1f129c6f03db8c. * Revert "try to get pull request id from github.event.workflow_run.pull_requests" This reverts commit 07517ce501c12e75da03d325c23968d75ac37d00. --- .github/workflows/get-api-diff.yml | 13 +++++++++++++ .github/workflows/report-api-diff.yml | 9 +-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/get-api-diff.yml b/.github/workflows/get-api-diff.yml index 6454de080c..eeb2fa0855 100644 --- a/.github/workflows/get-api-diff.yml +++ b/.github/workflows/get-api-diff.yml @@ -171,3 +171,16 @@ jobs: path: api-head.json - name: Kill Misskey Job run: screen -S misskey -X quit + + save-pr-number: + runs-on: ubuntu-latest + steps: + - name: Save PR number + env: + PR_NUMBER: ${{ github.event.number }} + run: | + echo "$PR_NUMBER" > ./pr_number + - uses: actions/upload-artifact@v3 + with: + name: api-artifact + path: pr_number diff --git a/.github/workflows/report-api-diff.yml b/.github/workflows/report-api-diff.yml index 9e7f47f923..55d13100fb 100644 --- a/.github/workflows/report-api-diff.yml +++ b/.github/workflows/report-api-diff.yml @@ -39,14 +39,7 @@ jobs: run: unzip api-artifact.zip -d artifacts - name: Load PR Number id: load-pr-num - env: - PULL_REQUESTS: ${{ toJson(github.event.workflow_run.pull_requests.*) }} - REPO_ID: ${{ github.repository_id }} - run: | - # find first pull requests that targets this repository - PR_NUMBER="$(echo "$PULL_REQUESTS" \ - | jq --arg REPO_ID "$REPO_ID" '[.[] | select ($REPO_ID == (.base.repo.id | tostring)) | .number ][0]')" - echo "pr-number=$PR_NUMBER" >> "$GITHUB_OUTPUT" + run: echo "pr-number=$(cat artifacts/pr_number)" >> "$GITHUB_OUTPUT" - name: Output base run: cat ./artifacts/api-base.json From 0c730968a363482a36f20ddec0a77eef1fd8639e Mon Sep 17 00:00:00 2001 From: yukineko <27853966+hideki0403@users.noreply.github.com> Date: Tue, 24 Oct 2023 14:34:32 +0900 Subject: [PATCH 03/20] =?UTF-8?q?fix:=20Redis=E3=81=B8=E3=81=AETL=E3=82=AD?= =?UTF-8?q?=E3=83=A3=E3=83=83=E3=82=B7=E3=83=A5=E3=81=8C=E6=9C=89=E5=8A=B9?= =?UTF-8?q?=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=ABHTL/LTL/STL/=E3=83=AA?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=8C=E7=A9=BA=E3=81=AB=E3=81=AA=E3=82=8B?= =?UTF-8?q?=E3=81=93=E3=81=A8=E3=81=8C=E3=81=82=E3=82=8B=E5=95=8F=E9=A1=8C?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3=20(#12088)=20(#12124)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: RedisTimelineが有効の場合にHTLがリセットされた状態になる問題を修正 * add: CHANGELOG.md * fix: LTL, STLでもTLが空になることがある問題を修正 * update: CHANGELOG.md * fix: DBへのフォールバック時にwithRenotesが考慮されていないのを修正 * feat: リストにもDBフォールバックを実装 * fix: リストのDBフォールバック時の挙動を修正 --------- Co-authored-by: syuilo --- CHANGELOG.md | 1 + .../api/endpoints/notes/hybrid-timeline.ts | 14 +- .../api/endpoints/notes/local-timeline.ts | 14 +- .../server/api/endpoints/notes/timeline.ts | 24 ++- .../api/endpoints/notes/user-list-timeline.ts | 150 ++++++++++++++---- 5 files changed, 154 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc89995cf7..0f875b4b70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Fix: リストTLに自分のフォロワー限定投稿が含まれない問題を修正 - Fix: ローカルタイムラインに投稿者自身の投稿への返信が含まれない問題を修正 - Fix: 自分のフォローしているユーザーの自分のフォローしていないユーザーの visibility: followers な投稿への返信がストリーミングで流れてくる問題を修正 +- Fix: RedisへのTLキャッシュが有効の場合にHTL/LTL/STLが空になることがある問題を修正 ## 2023.10.2 diff --git a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts index 518c34b949..7d0c9f1185 100644 --- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts @@ -131,6 +131,8 @@ export default class extends Endpoint { // eslint- shouldFallbackToDb = shouldFallbackToDb || (noteIds.length === 0); + let redisTimeline: MiNote[] = []; + if (!shouldFallbackToDb) { const query = this.notesRepository.createQueryBuilder('note') .where('note.id IN (:...noteIds)', { noteIds: noteIds }) @@ -141,9 +143,9 @@ export default class extends Endpoint { // eslint- .leftJoinAndSelect('renote.user', 'renoteUser') .leftJoinAndSelect('note.channel', 'channel'); - let timeline = await query.getMany(); + redisTimeline = await query.getMany(); - timeline = timeline.filter(note => { + redisTimeline = redisTimeline.filter(note => { if (note.userId === me.id) { return true; } @@ -159,15 +161,15 @@ export default class extends Endpoint { // eslint- return true; }); - // TODO: フィルタした結果件数が足りなかった場合の対応 - - timeline.sort((a, b) => a.id > b.id ? -1 : 1); + redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1); + } + if (redisTimeline.length > 0) { process.nextTick(() => { this.activeUsersChart.read(me); }); - return await this.noteEntityService.packMany(timeline, me); + return await this.noteEntityService.packMany(redisTimeline, me); } else { // fallback to db return await this.getFromDb({ untilId, diff --git a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts index 879f71a2f6..94a640e70a 100644 --- a/packages/backend/src/server/api/endpoints/notes/local-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/local-timeline.ts @@ -110,6 +110,8 @@ export default class extends Endpoint { // eslint- noteIds = noteIds.slice(0, ps.limit); + let redisTimeline: MiNote[] = []; + if (noteIds.length > 0) { const query = this.notesRepository.createQueryBuilder('note') .where('note.id IN (:...noteIds)', { noteIds: noteIds }) @@ -120,9 +122,9 @@ export default class extends Endpoint { // eslint- .leftJoinAndSelect('renote.user', 'renoteUser') .leftJoinAndSelect('note.channel', 'channel'); - let timeline = await query.getMany(); + redisTimeline = await query.getMany(); - timeline = timeline.filter(note => { + redisTimeline = redisTimeline.filter(note => { if (me && (note.userId === me.id)) { return true; } @@ -139,17 +141,17 @@ export default class extends Endpoint { // eslint- return true; }); - // TODO: フィルタした結果件数が足りなかった場合の対応 - - timeline.sort((a, b) => a.id > b.id ? -1 : 1); + redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1); + } + if (redisTimeline.length > 0) { process.nextTick(() => { if (me) { this.activeUsersChart.read(me); } }); - return await this.noteEntityService.packMany(timeline, me); + return await this.noteEntityService.packMany(redisTimeline, me); } else { // fallback to db return await this.getFromDb({ untilId, diff --git a/packages/backend/src/server/api/endpoints/notes/timeline.ts b/packages/backend/src/server/api/endpoints/notes/timeline.ts index c435fa7ec9..ac88c1f82b 100644 --- a/packages/backend/src/server/api/endpoints/notes/timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/timeline.ts @@ -5,7 +5,7 @@ import { Brackets } from 'typeorm'; import { Inject, Injectable } from '@nestjs/common'; -import type { NotesRepository } from '@/models/_.js'; +import type { MiNote, NotesRepository } from '@/models/_.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { QueryService } from '@/core/QueryService.js'; import ActiveUsersChart from '@/core/chart/charts/active-users.js'; @@ -89,6 +89,8 @@ export default class extends Endpoint { // eslint- let noteIds = await this.funoutTimelineService.get(ps.withFiles ? `homeTimelineWithFiles:${me.id}` : `homeTimeline:${me.id}`, untilId, sinceId); noteIds = noteIds.slice(0, ps.limit); + let redisTimeline: MiNote[] = []; + if (noteIds.length > 0) { const query = this.notesRepository.createQueryBuilder('note') .where('note.id IN (:...noteIds)', { noteIds: noteIds }) @@ -99,9 +101,9 @@ export default class extends Endpoint { // eslint- .leftJoinAndSelect('renote.user', 'renoteUser') .leftJoinAndSelect('note.channel', 'channel'); - let timeline = await query.getMany(); + redisTimeline = await query.getMany(); - timeline = timeline.filter(note => { + redisTimeline = redisTimeline.filter(note => { if (note.userId === me.id) { return true; } @@ -120,15 +122,15 @@ export default class extends Endpoint { // eslint- return true; }); - // TODO: フィルタした結果件数が足りなかった場合の対応 - - timeline.sort((a, b) => a.id > b.id ? -1 : 1); + redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1); + } + if (redisTimeline.length > 0) { process.nextTick(() => { this.activeUsersChart.read(me); }); - return await this.noteEntityService.packMany(timeline, me); + return await this.noteEntityService.packMany(redisTimeline, me); } else { // fallback to db return await this.getFromDb({ untilId, @@ -138,6 +140,7 @@ export default class extends Endpoint { // eslint- includeRenotedMyNotes: ps.includeRenotedMyNotes, includeLocalRenotes: ps.includeLocalRenotes, withFiles: ps.withFiles, + withRenotes: ps.withRenotes, }, me); } } else { @@ -149,12 +152,13 @@ export default class extends Endpoint { // eslint- includeRenotedMyNotes: ps.includeRenotedMyNotes, includeLocalRenotes: ps.includeLocalRenotes, withFiles: ps.withFiles, + withRenotes: ps.withRenotes, }, me); } }); } - private async getFromDb(ps: { untilId: string | null; sinceId: string | null; limit: number; includeMyRenotes: boolean; includeRenotedMyNotes: boolean; includeLocalRenotes: boolean; withFiles: boolean; }, me: MiLocalUser) { + private async getFromDb(ps: { untilId: string | null; sinceId: string | null; limit: number; includeMyRenotes: boolean; includeRenotedMyNotes: boolean; includeLocalRenotes: boolean; withFiles: boolean; withRenotes: boolean; }, me: MiLocalUser) { const followees = await this.userFollowingService.getFollowees(me.id); //#region Construct query @@ -222,6 +226,10 @@ export default class extends Endpoint { // eslint- if (ps.withFiles) { query.andWhere('note.fileIds != \'{}\''); } + + if (ps.withRenotes === false) { + query.andWhere('note.renoteId IS NULL'); + } //#endregion const timeline = await query.limit(ps.limit).getMany(); diff --git a/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts b/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts index 96e1e94f7c..9ead1410c2 100644 --- a/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/user-list-timeline.ts @@ -4,7 +4,7 @@ */ import { Inject, Injectable } from '@nestjs/common'; -import type { NotesRepository, UserListsRepository } from '@/models/_.js'; +import type { MiNote, NotesRepository, UserListMembershipsRepository, UserListsRepository } from '@/models/_.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; import ActiveUsersChart from '@/core/chart/charts/active-users.js'; @@ -13,7 +13,9 @@ import { CacheService } from '@/core/CacheService.js'; import { IdService } from '@/core/IdService.js'; import { isUserRelated } from '@/misc/is-user-related.js'; import { FunoutTimelineService } from '@/core/FunoutTimelineService.js'; +import { QueryService } from '@/core/QueryService.js'; import { ApiError } from '../../error.js'; +import { Brackets } from 'typeorm'; export const meta = { tags: ['notes', 'lists'], @@ -70,11 +72,16 @@ export default class extends Endpoint { // eslint- @Inject(DI.userListsRepository) private userListsRepository: UserListsRepository, + @Inject(DI.userListMembershipsRepository) + private userListMembershipsRepository: UserListMembershipsRepository, + private noteEntityService: NoteEntityService, private activeUsersChart: ActiveUsersChart, private cacheService: CacheService, private idService: IdService, private funoutTimelineService: FunoutTimelineService, + private queryService: QueryService, + ) { super(meta, paramDef, async (ps, me) => { const untilId = ps.untilId ?? (ps.untilDate ? this.idService.gen(ps.untilDate!) : null); @@ -102,44 +109,129 @@ export default class extends Endpoint { // eslint- let noteIds = await this.funoutTimelineService.get(ps.withFiles ? `userListTimelineWithFiles:${list.id}` : `userListTimeline:${list.id}`, untilId, sinceId); noteIds = noteIds.slice(0, ps.limit); - if (noteIds.length === 0) { - return []; + let redisTimeline: MiNote[] = []; + + if (noteIds.length > 0) { + const query = this.notesRepository.createQueryBuilder('note') + .where('note.id IN (:...noteIds)', { noteIds: noteIds }) + .innerJoinAndSelect('note.user', 'user') + .leftJoinAndSelect('note.reply', 'reply') + .leftJoinAndSelect('note.renote', 'renote') + .leftJoinAndSelect('reply.user', 'replyUser') + .leftJoinAndSelect('renote.user', 'renoteUser') + .leftJoinAndSelect('note.channel', 'channel'); + + redisTimeline = await query.getMany(); + + redisTimeline = redisTimeline.filter(note => { + if (note.userId === me.id) { + return true; + } + if (isUserRelated(note, userIdsWhoBlockingMe)) return false; + if (isUserRelated(note, userIdsWhoMeMuting)) return false; + if (note.renoteId) { + if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) { + if (isUserRelated(note, userIdsWhoMeMutingRenotes)) return false; + if (ps.withRenotes === false) return false; + } + } + + return true; + }); + + redisTimeline.sort((a, b) => a.id > b.id ? -1 : 1); } - const query = this.notesRepository.createQueryBuilder('note') - .where('note.id IN (:...noteIds)', { noteIds: noteIds }) - .innerJoinAndSelect('note.user', 'user') - .leftJoinAndSelect('note.reply', 'reply') - .leftJoinAndSelect('note.renote', 'renote') - .leftJoinAndSelect('reply.user', 'replyUser') - .leftJoinAndSelect('renote.user', 'renoteUser') - .leftJoinAndSelect('note.channel', 'channel'); + if (redisTimeline.length > 0) { + this.activeUsersChart.read(me); + return await this.noteEntityService.packMany(redisTimeline, me); + } else { // fallback to db + //#region Construct query + const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId) + .innerJoin(this.userListMembershipsRepository.metadata.targetName, 'userListMemberships', 'userListMemberships.userId = note.userId') + .innerJoinAndSelect('note.user', 'user') + .leftJoinAndSelect('note.reply', 'reply') + .leftJoinAndSelect('note.renote', 'renote') + .leftJoinAndSelect('reply.user', 'replyUser') + .leftJoinAndSelect('renote.user', 'renoteUser') + .andWhere('userListMemberships.userListId = :userListId', { userListId: list.id }) + .andWhere('note.channelId IS NULL') // チャンネルノートではない + .andWhere(new Brackets(qb => { + qb + .where('note.replyId IS NULL') // 返信ではない + .orWhere(new Brackets(qb => { + qb // 返信だけど投稿者自身への返信 + .where('note.replyId IS NOT NULL') + .andWhere('note.replyUserId = note.userId'); + })) + .orWhere(new Brackets(qb => { + qb // 返信だけど自分宛ての返信 + .where('note.replyId IS NOT NULL') + .andWhere('note.replyUserId = :meId', { meId: me.id }); + })) + .orWhere(new Brackets(qb => { + qb // 返信だけどwithRepliesがtrueの場合 + .where('note.replyId IS NOT NULL') + .andWhere('userListMemberships.withReplies = true'); + })); + })); - let timeline = await query.getMany(); + this.queryService.generateVisibilityQuery(query, me); + this.queryService.generateMutedUserQuery(query, me); + this.queryService.generateBlockedUserQuery(query, me); + this.queryService.generateMutedUserRenotesQueryForNotes(query, me); - timeline = timeline.filter(note => { - if (note.userId === me.id) { - return true; - } - if (isUserRelated(note, userIdsWhoBlockingMe)) return false; - if (isUserRelated(note, userIdsWhoMeMuting)) return false; - if (note.renoteId) { - if (note.text == null && note.fileIds.length === 0 && !note.hasPoll) { - if (isUserRelated(note, userIdsWhoMeMutingRenotes)) return false; - if (ps.withRenotes === false) return false; - } + if (ps.includeMyRenotes === false) { + query.andWhere(new Brackets(qb => { + qb.orWhere('note.userId != :meId', { meId: me.id }); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); } - return true; - }); + if (ps.includeRenotedMyNotes === false) { + query.andWhere(new Brackets(qb => { + qb.orWhere('note.renoteUserId != :meId', { meId: me.id }); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); + } - // TODO: フィルタした結果件数が足りなかった場合の対応 + if (ps.includeLocalRenotes === false) { + query.andWhere(new Brackets(qb => { + qb.orWhere('note.renoteUserHost IS NOT NULL'); + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + qb.orWhere('0 < (SELECT COUNT(*) FROM poll WHERE poll."noteId" = note.id)'); + })); + } - timeline.sort((a, b) => a.id > b.id ? -1 : 1); + if (ps.withRenotes === false) { + query.andWhere(new Brackets(qb => { + qb.orWhere('note.renoteId IS NULL'); + qb.orWhere(new Brackets(qb => { + qb.orWhere('note.text IS NOT NULL'); + qb.orWhere('note.fileIds != \'{}\''); + })); + })); + } - this.activeUsersChart.read(me); + if (ps.withFiles) { + query.andWhere('note.fileIds != \'{}\''); + } + //#endregion - return await this.noteEntityService.packMany(timeline, me); + const timeline = await query.limit(ps.limit).getMany(); + + this.activeUsersChart.read(me); + + return await this.noteEntityService.packMany(timeline, me); + } }); } } From afb37f0b0395c208a767b2e78e027f4426116e91 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 24 Oct 2023 14:38:15 +0900 Subject: [PATCH 04/20] :art: --- .../src/server/api/endpoints/get-avatar-decorations.ts | 5 ++++- packages/frontend/src/pages/settings/profile.vue | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/endpoints/get-avatar-decorations.ts b/packages/backend/src/server/api/endpoints/get-avatar-decorations.ts index ec602a0dc5..dbe1626149 100644 --- a/packages/backend/src/server/api/endpoints/get-avatar-decorations.ts +++ b/packages/backend/src/server/api/endpoints/get-avatar-decorations.ts @@ -8,6 +8,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { DI } from '@/di-symbols.js'; import { AvatarDecorationService } from '@/core/AvatarDecorationService.js'; +import { RoleService } from '@/core/RoleService.js'; export const meta = { tags: ['users'], @@ -63,16 +64,18 @@ export const paramDef = { export default class extends Endpoint { // eslint-disable-line import/no-default-export constructor( private avatarDecorationService: AvatarDecorationService, + private roleService: RoleService, ) { super(meta, paramDef, async (ps, me) => { const decorations = await this.avatarDecorationService.getAll(true); + const allRoles = await this.roleService.getRoles(); return decorations.map(decoration => ({ id: decoration.id, name: decoration.name, description: decoration.description, url: decoration.url, - roleIdsThatCanBeUsedThisDecoration: decoration.roleIdsThatCanBeUsedThisDecoration, + roleIdsThatCanBeUsedThisDecoration: decoration.roleIdsThatCanBeUsedThisDecoration.filter(roleId => allRoles.some(role => role.id === roleId)), })); }); } diff --git a/packages/frontend/src/pages/settings/profile.vue b/packages/frontend/src/pages/settings/profile.vue index 2a0b678ed1..2ac8d15545 100644 --- a/packages/frontend/src/pages/settings/profile.vue +++ b/packages/frontend/src/pages/settings/profile.vue @@ -96,6 +96,7 @@ SPDX-License-Identifier: AGPL-3.0-only >
{{ avatarDecoration.name }}
+ @@ -389,4 +390,10 @@ definePageMetadata({ font-weight: bold; margin-bottom: 20px; } + +.avatarDecorationLock { + position: absolute; + bottom: 12px; + right: 12px; +} From 024546206d17b728b67769091b4aa700df2181e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=93=E3=81=8B=E3=82=8A?= <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Wed, 25 Oct 2023 17:46:04 +0900 Subject: [PATCH 05/20] =?UTF-8?q?feat(AiScript):=20Mk:nyaize()=20=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=20(#12136)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(AiScript): Mk:nyaize * Update Changelog * Fix relative path --- CHANGELOG.md | 1 + packages/frontend/src/scripts/aiscript/api.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f875b4b70..c693748f67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ - Feat: プラグイン・テーマを外部サイトから直接インストールできるようになりました - 外部サイトでの実装が必要です。詳細は Misskey Hub をご覧ください https://misskey-hub.net/docs/advanced/publish-on-your-website.html +- Feat: AiScript関数`Mk:nyaize()`が追加されました - Fix: 投稿フォームでのユーザー変更がプレビューに反映されない問題を修正 ### Server diff --git a/packages/frontend/src/scripts/aiscript/api.ts b/packages/frontend/src/scripts/aiscript/api.ts index 032853f7ad..fb7ab924b7 100644 --- a/packages/frontend/src/scripts/aiscript/api.ts +++ b/packages/frontend/src/scripts/aiscript/api.ts @@ -9,6 +9,7 @@ import { $i } from '@/account.js'; import { miLocalStorage } from '@/local-storage.js'; import { customEmojis } from '@/custom-emojis.js'; import { url, lang } from '@/config.js'; +import { nyaize } from '@/scripts/nyaize.js'; export function createAiScriptEnv(opts) { return { @@ -71,5 +72,9 @@ export function createAiScriptEnv(opts) { 'Mk:url': values.FN_NATIVE(() => { return values.STR(window.location.href); }), + 'Mk:nyaize': values.FN_NATIVE(([text]) => { + utils.assertString(text); + return values.STR(nyaize(text.value)); + }), }; } From dc0582739f8c02be1b7297132872dffd8f3e4755 Mon Sep 17 00:00:00 2001 From: ikasoba <57828948+ikasoba@users.noreply.github.com> Date: Wed, 25 Oct 2023 21:19:43 +0900 Subject: [PATCH 06/20] =?UTF-8?q?Fix:=20STL=E3=81=A7=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=81=97=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=83=81=E3=83=A3=E3=83=B3=E3=83=8D=E3=83=AB=E3=81=8C=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E3=81=95=E3=82=8C=E3=82=8B=E5=95=8F=E9=A1=8C=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20(#12143)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * タイムラインをpostgresから取得する際にフォローしていないチャンネルが取得されるのを修正 * CHANGELOGに追記 --- CHANGELOG.md | 1 + .../api/endpoints/notes/hybrid-timeline.ts | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c693748f67..3decae2b9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - Fix: ローカルタイムラインに投稿者自身の投稿への返信が含まれない問題を修正 - Fix: 自分のフォローしているユーザーの自分のフォローしていないユーザーの visibility: followers な投稿への返信がストリーミングで流れてくる問題を修正 - Fix: RedisへのTLキャッシュが有効の場合にHTL/LTL/STLが空になることがある問題を修正 +- Fix: STLでフォローしていないチャンネルが取得される問題を修正 ## 2023.10.2 diff --git a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts index 7d0c9f1185..4eeec563d7 100644 --- a/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts +++ b/packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts @@ -5,7 +5,7 @@ import { Brackets } from 'typeorm'; import { Inject, Injectable } from '@nestjs/common'; -import type { NotesRepository, FollowingsRepository, MiNote } from '@/models/_.js'; +import type { NotesRepository, FollowingsRepository, MiNote, ChannelFollowingsRepository } from '@/models/_.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import ActiveUsersChart from '@/core/chart/charts/active-users.js'; import { NoteEntityService } from '@/core/entities/NoteEntityService.js'; @@ -69,6 +69,9 @@ export default class extends Endpoint { // eslint- @Inject(DI.notesRepository) private notesRepository: NotesRepository, + @Inject(DI.channelFollowingsRepository) + private channelFollowingsRepository: ChannelFollowingsRepository, + private noteEntityService: NoteEntityService, private roleService: RoleService, private activeUsersChart: ActiveUsersChart, @@ -208,6 +211,11 @@ export default class extends Endpoint { // eslint- withReplies: boolean, }, me: MiLocalUser) { const followees = await this.userFollowingService.getFollowees(me.id); + const followingChannels = await this.channelFollowingsRepository.find({ + where: { + followerId: me.id, + }, + }); const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId) .andWhere(new Brackets(qb => { @@ -226,6 +234,14 @@ export default class extends Endpoint { // eslint- .leftJoinAndSelect('reply.user', 'replyUser') .leftJoinAndSelect('renote.user', 'renoteUser'); + if (followingChannels.length > 0) { + const followingChannelIds = followingChannels.map(x => x.followeeId); + + query.andWhere('note.channelId IN (:...followingChannelIds) OR note.channelId IS NULL', { followingChannelIds }); + } else { + query.andWhere('note.channelId IS NULL'); + } + if (!ps.withReplies) { query.andWhere(new Brackets(qb => { qb From 1d9b5ae1ba6d98cb496367d955fd691371d31f71 Mon Sep 17 00:00:00 2001 From: Lya <114819113+L-y-a@users.noreply.github.com> Date: Wed, 25 Oct 2023 21:20:36 +0900 Subject: [PATCH 07/20] =?UTF-8?q?chore(frontend):=20=E7=B5=B5=E6=96=87?= =?UTF-8?q?=E5=AD=97=E5=90=8D=E3=81=AE=E3=83=95=E3=82=A3=E3=83=BC=E3=83=AB?= =?UTF-8?q?=E3=83=89=E3=81=A7autocapitalize=E3=81=97=E3=81=AA=E3=81=84?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=20(#12139)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/frontend/src/components/MkEmojiPicker.vue | 2 +- packages/frontend/src/components/MkInput.vue | 2 ++ packages/frontend/src/pages/about.emojis.vue | 2 +- packages/frontend/src/pages/custom-emojis-manager.vue | 4 ++-- packages/frontend/src/pages/emoji-edit-dialog.vue | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/frontend/src/components/MkEmojiPicker.vue b/packages/frontend/src/components/MkEmojiPicker.vue index 7eff637482..5b420c499e 100644 --- a/packages/frontend/src/components/MkEmojiPicker.vue +++ b/packages/frontend/src/components/MkEmojiPicker.vue @@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only