2

I have an SQLite DB in my project in which I inserted chat conversations. So,I want to delete those conversations that are inactivated(No insertions) since last 5 Mins. what is the best way to achieve this? I thought for initializing a CountDownTimer while inserting each item into DB and reset it when new item gets inserted. Is it a good approach?

Krupa Patel
  • 3,309
  • 3
  • 23
  • 28
Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109

2 Answers2

0

I created a service that checks the database every five minutes and deletes inactive chats. For now, it works for me. But if there is any better approach, please let me know so that I would refactor it.

Seshu Vinay
  • 13,560
  • 9
  • 60
  • 109
-1

It's suggested here that it's not recommended. However, you can run your delete query every several minutes, deleting what you don't need.

DELETE FROM MyTable WHERE datediff(now(), myTimestamp) >= 14;

Or select only what you need, since plain text in DB takes so little space.

SELECT * FROM myTable WHERE timetampColumn>=date_sub(now(), interval 2 week);
Community
  • 1
  • 1
Marius
  • 810
  • 7
  • 20