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?
Asked
Active
Viewed 141 times
2

Krupa Patel
- 3,309
- 3
- 23
- 28

Seshu Vinay
- 13,560
- 9
- 60
- 109
-
for this you have to post the schema of you tables... cant help w/o knowing how u are doing it.. – SMR Jun 20 '14 at 04:55
-
@SMR I just want to know a better approach to achieve it. How is it related to DB schema? – Seshu Vinay Jun 20 '14 at 05:08
-
@SeshuVinay,can you please let me know how you can differ which conversion is inactive or active? – Haresh Chhelana Jun 20 '14 at 05:16
-
Have to check time of the last entry with userId @Haresh – Seshu Vinay Jun 20 '14 at 05:25
-
That's why I thought of starting a countdowntimer for each conversation. – Seshu Vinay Jun 20 '14 at 05:27
-
What time interval have you define for getting latest conversion ? – Haresh Chhelana Jun 20 '14 at 05:32
-
I don't know what time interval you are talking about? For now, I thought of starting a countdown timer while inserting a chat message in a convrsation and when a new message inserts in the same conversation, resetting the timer(cancel and start). – Seshu Vinay Jun 20 '14 at 05:49
-
Is there a better approach? – Seshu Vinay Jun 20 '14 at 05:49
2 Answers
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);
-
@CL. I'm pretty sure OP could manage to 'convert' these to what SQLite understands. – Marius Jun 20 '14 at 06:50