From bdc7188f8b52eceaf45e773714f5e09b8120154f Mon Sep 17 00:00:00 2001 From: MaysWind Date: Mon, 18 Jan 2021 01:23:54 +0800 Subject: [PATCH] fix database selection or db transaction usage bug --- pkg/services/accounts.go | 2 +- pkg/services/transaction_categories.go | 2 +- pkg/services/transaction_tags.go | 2 +- pkg/services/transactions.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/services/accounts.go b/pkg/services/accounts.go index 573d1459..b2d8f06d 100644 --- a/pkg/services/accounts.go +++ b/pkg/services/accounts.go @@ -274,7 +274,7 @@ func (s *AccountService) DeleteAccount(uid int64, accountId int64) error { return s.UserDataDB(uid).DoTransaction(func(sess *xorm.Session) error { var accountAndSubAccounts []*models.Account - err := s.UserDataDB(uid).Where("uid=? AND deleted=? AND (account_id=? OR parent_account_id=?)", uid, false, accountId, accountId).Find(&accountAndSubAccounts) + err := sess.Where("uid=? AND deleted=? AND (account_id=? OR parent_account_id=?)", uid, false, accountId, accountId).Find(&accountAndSubAccounts) if err != nil { return err diff --git a/pkg/services/transaction_categories.go b/pkg/services/transaction_categories.go index 17e3822f..7c083a7e 100644 --- a/pkg/services/transaction_categories.go +++ b/pkg/services/transaction_categories.go @@ -282,7 +282,7 @@ func (s *TransactionCategoryService) DeleteCategory(uid int64, categoryId int64) return s.UserDataDB(uid).DoTransaction(func(sess *xorm.Session) error { var categoryAndSubCategories []*models.TransactionCategory - err := s.UserDataDB(uid).Where("uid=? AND deleted=? AND (category_id=? OR parent_category_id=?)", uid, false, categoryId, categoryId).Find(&categoryAndSubCategories) + err := sess.Where("uid=? AND deleted=? AND (category_id=? OR parent_category_id=?)", uid, false, categoryId, categoryId).Find(&categoryAndSubCategories) if err != nil { return err diff --git a/pkg/services/transaction_tags.go b/pkg/services/transaction_tags.go index b55bdfb1..8c7c922d 100644 --- a/pkg/services/transaction_tags.go +++ b/pkg/services/transaction_tags.go @@ -290,7 +290,7 @@ func (s *TransactionTagService) ExistsTagName(uid int64, name string) (bool, err return false, errs.ErrTransactionTagNameIsEmpty } - return s.UserDB().Cols("name").Where("uid=? AND deleted=? AND name=?", uid, false, name).Exist(&models.TransactionTag{}) + return s.UserDataDB(uid).Cols("name").Where("uid=? AND deleted=? AND name=?", uid, false, name).Exist(&models.TransactionTag{}) } // GetTagMapByList returns a transaction tag map by a list diff --git a/pkg/services/transactions.go b/pkg/services/transactions.go index bc772e95..f97af1a4 100644 --- a/pkg/services/transactions.go +++ b/pkg/services/transactions.go @@ -464,7 +464,7 @@ func (s *TransactionService) ModifyTransaction(transaction *models.Transaction, } } - err := s.UserDB().DoTransaction(func(sess *xorm.Session) error { + err := s.UserDataDB(transaction.Uid).DoTransaction(func(sess *xorm.Session) error { // Get and verify current transaction oldTransaction := &models.Transaction{} has, err := sess.ID(transaction.TransactionId).Where("uid=? AND deleted=?", transaction.Uid, false).Get(oldTransaction)