Skip to content

Commit

Permalink
fix multiple transaction being created in array query of remove, count
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwalguptaofficial committed May 20, 2021
1 parent cbcf9b4 commit a4b3edd
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 23 deletions.
3 changes: 1 addition & 2 deletions src/worker/executors/count/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,17 @@ export class Count extends BaseFetch {
this.resultCount = results.length;
});
};
this.initTransaction_();
if (query.join == null) {
if (query.where != null) {
if ((query.where as WhereQuery).or || isArray(this.query.where)) {
result = getDataFromSelect();
}
else {
this.initTransaction_();
result = this.goToWhereLogic();
}
}
else {
this.initTransaction_();
result = this.executeWhereUndefinedLogic() as any;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/worker/executors/remove/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class Remove extends BaseFetch {
results = null;
const whereQry = { [pkey]: { [QUERY_OPTION.In]: keyList } };
this.query[QUERY_OPTION.Where] = whereQry;
this.initTransaction_();
return this.processWhere_();
})
}
Expand Down
6 changes: 0 additions & 6 deletions src/worker/executors/select/base_select.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { Select } from "./index";

// declare module "./index" {
// interface Select {
// methodY(): void;
// }
// }

export const setPushResult = function (this: Select) {
if (this.query.case) {
this.pushResult = (value) => {
Expand Down
5 changes: 1 addition & 4 deletions src/worker/executors/select/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ export class Select extends BaseFetch {
}
else {
this.results = output;
// if (this.isSubQuery === true) {
// return this.returnResult_();
// }
}

};
Expand All @@ -176,7 +173,7 @@ export class Select extends BaseFetch {

private initTransaction_() {
if (!this.isTxQuery) {
this.util.createTransaction([this.tableName], IDB_MODE.ReadOnly);
this.util.createTransactionIfNotExist([this.tableName], IDB_MODE.ReadOnly);
}
this.objectStore = this.util.objectStore(this.tableName);
}
Expand Down
13 changes: 3 additions & 10 deletions src/worker/executors/select/join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ export class Join {
}

private executeSelect(query: SelectQuery) {
this.select.util.emptyTx();
return new Select(query, this.select.util).
execute(this.select.db);
}

execute() {
const query = this.select.query;
const query = this.query;
if (getDataType(query.join) === DATA_TYPE.Object) {
this.joinQueryStack_ = [query.join as JoinQuery];
}
Expand All @@ -63,7 +64,7 @@ export class Join {
}

private onJoinQueryFinished_() {
const query = this.query;
// const query = this.query;
if (this.results.length > 0) {

try {
Expand Down Expand Up @@ -125,14 +126,6 @@ export class Join {
new LogHelper(ERROR_TYPE.InvalidJoinQuery, ex.message)
);
}

// if (this.query.skip && this.query.limit) {
// this.results.splice(0, this.query.skip);
// this.results = this.results.slice(0, this.query.limit);
// }
// else if (this.query.limit) {
// this.results = this.results.slice(0, this.query.limit);
// }
}
return;
}
Expand Down
7 changes: 7 additions & 0 deletions src/worker/idbutil/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export class IDBUtil {
this.tx.onerror = null;
this.tx = null;
}

createTransactionIfNotExist(tables: string[], mode?: IDB_MODE) {
if (!this.tx) {
this.createTransaction(tables, mode);
}
}

createTransaction(tables: string[], mode = IDB_MODE.ReadWrite) {
this.tx = this.con.transaction(tables, mode);
return promise((res, rej) => {
Expand Down

0 comments on commit a4b3edd

Please sign in to comment.