Skip to content

Commit

Permalink
db optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
DevEmperor committed Feb 2, 2024
1 parent c68b126 commit b5123c2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ public void edit(Context context, long id, ChatItem item) throws IOException, JS

public void delete(Context context, long id) {
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("DELETE FROM CHAT_HISTORY_TABLE WHERE ID=" + id, null);
cursor.moveToFirst();
cursor.close();
db.delete("CHAT_HISTORY_TABLE", "ID=" + id, null);
db.close();

String filePath = context.getFilesDir().getAbsolutePath() + "/chat_" + id + ".json";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void reset() {
}

public List<UsageModel> getAll() {
SQLiteDatabase db = this.getWritableDatabase();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM USAGE", null);

List<UsageModel> models = new ArrayList<>();
Expand All @@ -79,7 +79,7 @@ public List<UsageModel> getAll() {
}

public double getTotalCost() {
SQLiteDatabase db = this.getWritableDatabase();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT SUM(COST) FROM USAGE", null);

double totalCost = 0;
Expand Down

0 comments on commit b5123c2

Please sign in to comment.