tambah fungsi hapus data biar database ga gendut

This commit is contained in:
Kusaeni 2024-10-02 19:49:30 +07:00
parent 8b2d9222d2
commit 628b941f20
2 changed files with 26 additions and 2 deletions

24
hapus_data.py Normal file
View file

@ -0,0 +1,24 @@
from sqlalchemy import desc
from models import Notifikasi, Session
session = Session()
def hapus_notif():
lima = session.query(Notifikasi).order_by(desc(Notifikasi.id)).limit(5)
aman = []
for item in lima:
id = item.id
aman.append(id)
session.query(Notifikasi).filter(Notifikasi.id.not_in(aman)).delete(
synchronize_session="fetch"
)
session.commit()
hapus_notif()

View file

@ -168,8 +168,8 @@ async def jalan():
await getNotif() await getNotif()
await asyncio.sleep(5) await asyncio.sleep(5)
await kirim_ke_tele() await kirim_ke_tele()
# await asyncio.sleep(5) await asyncio.sleep(5)
# await tandai_notif() await tandai_notif()
# #