fix(beatmap): do not add to database when existed
This commit is contained in:
@@ -14,7 +14,7 @@ from .beatmapset import Beatmapset, BeatmapsetResp
|
|||||||
|
|
||||||
from redis.asyncio import Redis
|
from redis.asyncio import Redis
|
||||||
from sqlalchemy import Column, DateTime
|
from sqlalchemy import Column, DateTime
|
||||||
from sqlmodel import VARCHAR, Field, Relationship, SQLModel, col, func, select
|
from sqlmodel import VARCHAR, Field, Relationship, SQLModel, col, exists, func, select
|
||||||
from sqlmodel.ext.asyncio.session import AsyncSession
|
from sqlmodel.ext.asyncio.session import AsyncSession
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -80,8 +80,11 @@ class Beatmap(BeatmapBase, table=True):
|
|||||||
"beatmap_status": BeatmapRankStatus(resp.ranked),
|
"beatmap_status": BeatmapRankStatus(resp.ranked),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
session.add(beatmap)
|
if not (
|
||||||
await session.commit()
|
await session.exec(select(exists()).where(Beatmap.id == resp.id))
|
||||||
|
).first():
|
||||||
|
session.add(beatmap)
|
||||||
|
await session.commit()
|
||||||
beatmap = (
|
beatmap = (
|
||||||
await session.exec(select(Beatmap).where(Beatmap.id == resp.id))
|
await session.exec(select(Beatmap).where(Beatmap.id == resp.id))
|
||||||
).first()
|
).first()
|
||||||
@@ -106,7 +109,10 @@ class Beatmap(BeatmapBase, table=True):
|
|||||||
"beatmap_status": BeatmapRankStatus(resp.ranked),
|
"beatmap_status": BeatmapRankStatus(resp.ranked),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
session.add(beatmap)
|
if not (
|
||||||
|
await session.exec(select(exists()).where(Beatmap.id == resp.id))
|
||||||
|
).first():
|
||||||
|
session.add(beatmap)
|
||||||
beatmaps.append(beatmap)
|
beatmaps.append(beatmap)
|
||||||
await session.commit()
|
await session.commit()
|
||||||
return beatmaps
|
return beatmaps
|
||||||
|
|||||||
Reference in New Issue
Block a user