mirror of
https://github.com/NoCrypt/migu.git
synced 2026-04-19 15:42:05 +00:00
fix: unnecessary list queries
This commit is contained in:
parent
0468f345dc
commit
83e4d30d25
4 changed files with 61 additions and 35 deletions
1
common/modules/al.d.ts
vendored
1
common/modules/al.d.ts
vendored
|
|
@ -149,6 +149,7 @@ export type Viewer = {
|
|||
}
|
||||
name: string
|
||||
id: number
|
||||
sync: boolean
|
||||
mediaListOptions?: {
|
||||
animeList?: {
|
||||
customLists?: string[]
|
||||
|
|
|
|||
|
|
@ -256,30 +256,36 @@ export default class Helper {
|
|||
}
|
||||
|
||||
Object.assign(variables, this.getFuzzyDate(media, status))
|
||||
if (media.mediaListEntry?.status !== variables.status || media.mediaListEntry?.progress !== variables.episode || media.mediaListEntry?.score !== variables.score || media.mediaListEntry?.repeat !== variables.repeat) {
|
||||
let res
|
||||
const description = `Title: ${anilistClient.title(media)}\nStatus: ${this.statusName[variables.status]}\nEpisode: ${videoEpisode} / ${media.episodes ? media.episodes : '?'}`
|
||||
if (this.isAniAuth()) {
|
||||
res = await anilistClient.alEntry(lists, variables)
|
||||
} else if (this.isMalAuth()) {
|
||||
res = await malClient.malEntry(media, variables)
|
||||
}
|
||||
this.listToast(res, description, false)
|
||||
|
||||
let res
|
||||
const description = `Title: ${anilistClient.title(media)}\nStatus: ${this.statusName[variables.status]}\nEpisode: ${videoEpisode} / ${media.episodes ? media.episodes : '?'}`
|
||||
if (this.isAniAuth()) {
|
||||
res = await anilistClient.alEntry(lists, variables)
|
||||
} else if (this.isMalAuth()) {
|
||||
res = await malClient.malEntry(media, variables)
|
||||
}
|
||||
this.listToast(res, description, false)
|
||||
|
||||
if (this.getUser().sync) { // handle profile entry syncing
|
||||
const mediaId = media.id
|
||||
for (const profile of get(profiles)) {
|
||||
if (profile.viewer?.data?.Viewer.sync) {
|
||||
let res
|
||||
if (profile.viewer?.data?.Viewer?.avatar) {
|
||||
const currentLists = (await anilistClient.getUserLists({userID: profile.viewer.data.Viewer.id, token: profile.token}))?.data?.MediaListCollection?.lists?.flatMap(list => list.entries).find(({ media }) => media.id === mediaId)?.media?.mediaListEntry?.customLists?.filter(list => list.enabled).map(list => list.name) || []
|
||||
res = await anilistClient.alEntry(currentLists, {...variables, token: profile.token})
|
||||
} else {
|
||||
res = await malClient.malEntry(media, {...variables, token: profile.token})
|
||||
if (this.getUser().sync) { // handle profile entry syncing
|
||||
const mediaId = media.id
|
||||
for (const profile of get(profiles)) {
|
||||
if (profile.viewer?.data?.Viewer.sync) {
|
||||
let res
|
||||
if (profile.viewer?.data?.Viewer?.avatar) {
|
||||
const currentLists = (await anilistClient.getUserLists({
|
||||
userID: profile.viewer.data.Viewer.id,
|
||||
token: profile.token
|
||||
}))?.data?.MediaListCollection?.lists?.flatMap(list => list.entries).find(({media}) => media.id === mediaId)?.media?.mediaListEntry?.customLists?.filter(list => list.enabled).map(list => list.name) || []
|
||||
res = await anilistClient.alEntry(currentLists, {...variables, token: profile.token})
|
||||
} else {
|
||||
res = await malClient.malEntry(media, {...variables, token: profile.token})
|
||||
}
|
||||
this.listToast(res, description, profile)
|
||||
}
|
||||
this.listToast(res, description, profile)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
debug(`No entry changes detected for ${media.title.userPreferred}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
common/modules/mal.d.ts
vendored
1
common/modules/mal.d.ts
vendored
|
|
@ -40,6 +40,7 @@ export type Viewer = {
|
|||
id: number
|
||||
name: string
|
||||
picture: string
|
||||
sync: boolean
|
||||
}
|
||||
|
||||
export type MediaList = {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@
|
|||
status = 'NOT IN LIST'
|
||||
if (media.mediaListEntry) {
|
||||
const res = await Helper.delete(Helper.isAniAuth() ? {id: media.mediaListEntry.id} : {idMal: media.idMal})
|
||||
const description = `${anilistClient.title(media)} has been deleted from your list`
|
||||
const description = `${anilistClient.title(media)} has been deleted from your list.`
|
||||
printToast(res, description, false, false)
|
||||
|
||||
if (res) media.mediaListEntry = undefined
|
||||
|
|
@ -99,25 +99,43 @@
|
|||
lists,
|
||||
...fuzzyDate
|
||||
}
|
||||
const res = await Helper.entry(media, variables)
|
||||
if (media?.mediaListEntry?.status !== variables.status || media?.mediaListEntry?.progress !== variables.episode || media?.mediaListEntry?.score !== variables.score || media?.mediaListEntry?.repeat !== variables.repeat) {
|
||||
const res = await Helper.entry(media, variables)
|
||||
|
||||
if (res?.data?.SaveMediaListEntry) { media.mediaListEntry = res?.data?.SaveMediaListEntry }
|
||||
if (res?.data?.SaveMediaListEntry) {
|
||||
media.mediaListEntry = res?.data?.SaveMediaListEntry
|
||||
}
|
||||
|
||||
const description = `Title: ${anilistClient.title(media)}\nStatus: ${Helper.statusName[status]}\nEpisode: ${episode} / ${totalEpisodes}${score !== 0 ? `\nYour Score: ${score}` : ''}`
|
||||
printToast(res, description, true, false)
|
||||
if (Helper.getUser().sync) { // handle profile syncing
|
||||
const mediaId = media.id
|
||||
for (const profile of get(profiles)) {
|
||||
if (profile.viewer?.data?.Viewer.sync) {
|
||||
const anilist = profile.viewer?.data?.Viewer?.avatar
|
||||
const currentLists = (anilist ? (await anilistClient.getUserLists({userID: profile.viewer.data.Viewer.id, token: profile.token}))?.data?.MediaListCollection?.lists?.flatMap(list => list.entries).find(({ media }) => media.id === mediaId)?.media?.mediaListEntry?.customLists?.filter(list => list.enabled).map(list => list.name) || [] : lists)
|
||||
if (!currentLists.includes('Watched using Miru')) {
|
||||
currentLists.push('Watched using Miru')
|
||||
const description = `Title: ${anilistClient.title(media)}\nStatus: ${Helper.statusName[status]}\nEpisode: ${episode} / ${totalEpisodes}${score !== 0 ? `\nYour Score: ${score}` : ''}`
|
||||
printToast(res, description, true, false)
|
||||
if (Helper.getUser().sync) { // handle profile syncing
|
||||
const mediaId = media.id
|
||||
for (const profile of get(profiles)) {
|
||||
if (profile.viewer?.data?.Viewer.sync) {
|
||||
const anilist = profile.viewer?.data?.Viewer?.avatar
|
||||
const currentLists = (anilist ? (await anilistClient.getUserLists({
|
||||
userID: profile.viewer.data.Viewer.id,
|
||||
token: profile.token
|
||||
}))?.data?.MediaListCollection?.lists?.flatMap(list => list.entries).find(({media}) => media.id === mediaId)?.media?.mediaListEntry?.customLists?.filter(list => list.enabled).map(list => list.name) || [] : lists)
|
||||
if (!currentLists.includes('Watched using Miru')) {
|
||||
currentLists.push('Watched using Miru')
|
||||
}
|
||||
const res = await Helper.entry(media, {
|
||||
...variables,
|
||||
lists: currentLists,
|
||||
score: (anilist ? (score * 10) : score),
|
||||
token: profile.token,
|
||||
anilist
|
||||
})
|
||||
printToast(res, description, true, profile)
|
||||
}
|
||||
const res = await Helper.entry(media, { ...variables, lists: currentLists, score: (anilist ? (score * 10) : score), token: profile.token, anilist })
|
||||
printToast(res, description, true, profile)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
toast.warning('No Changes to List', {
|
||||
description: `Title: ${anilistClient.title(media)}\nStatus: ${Helper.statusName[status]}\nEpisode: ${episode} / ${totalEpisodes}${score !== 0 ? `\nYour Score: ${score}` : ''}`,
|
||||
duration: 6000
|
||||
})
|
||||
}
|
||||
} else {
|
||||
await deleteEntry()
|
||||
|
|
|
|||
Loading…
Reference in a new issue