mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-20 01:34:24 +08:00
improve performance
This commit is contained in:
@@ -201,28 +201,25 @@ func (s *AccountService) CreateAccounts(c core.Context, mainAccount *models.Acco
|
|||||||
return errs.ErrUserIdInvalid
|
return errs.ErrUserIdInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
needAccountUuidCount := uint16(len(childrenAccounts) + 1)
|
||||||
|
accountUuids := s.GenerateUuids(uuid.UUID_TYPE_ACCOUNT, needAccountUuidCount)
|
||||||
|
|
||||||
|
if len(accountUuids) < int(needAccountUuidCount) {
|
||||||
|
return errs.ErrSystemIsBusy
|
||||||
|
}
|
||||||
|
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
|
|
||||||
allAccounts := make([]*models.Account, len(childrenAccounts)+1)
|
allAccounts := make([]*models.Account, len(childrenAccounts)+1)
|
||||||
var allInitTransactions []*models.Transaction
|
var allInitTransactions []*models.Transaction
|
||||||
|
|
||||||
mainAccount.AccountId = s.GenerateUuid(uuid.UUID_TYPE_ACCOUNT)
|
mainAccount.AccountId = accountUuids[0]
|
||||||
|
|
||||||
if mainAccount.AccountId < 1 {
|
|
||||||
return errs.ErrSystemIsBusy
|
|
||||||
}
|
|
||||||
|
|
||||||
allAccounts[0] = mainAccount
|
allAccounts[0] = mainAccount
|
||||||
|
|
||||||
if mainAccount.Type == models.ACCOUNT_TYPE_MULTI_SUB_ACCOUNTS {
|
if mainAccount.Type == models.ACCOUNT_TYPE_MULTI_SUB_ACCOUNTS {
|
||||||
for i := 0; i < len(childrenAccounts); i++ {
|
for i := 0; i < len(childrenAccounts); i++ {
|
||||||
childAccount := childrenAccounts[i]
|
childAccount := childrenAccounts[i]
|
||||||
childAccount.AccountId = s.GenerateUuid(uuid.UUID_TYPE_ACCOUNT)
|
childAccount.AccountId = accountUuids[i+1]
|
||||||
|
|
||||||
if childAccount.AccountId < 1 {
|
|
||||||
return errs.ErrSystemIsBusy
|
|
||||||
}
|
|
||||||
|
|
||||||
childAccount.ParentAccountId = mainAccount.AccountId
|
childAccount.ParentAccountId = mainAccount.AccountId
|
||||||
childAccount.Uid = mainAccount.Uid
|
childAccount.Uid = mainAccount.Uid
|
||||||
childAccount.Type = models.ACCOUNT_TYPE_SINGLE_ACCOUNT
|
childAccount.Type = models.ACCOUNT_TYPE_SINGLE_ACCOUNT
|
||||||
|
|||||||
@@ -229,14 +229,16 @@ func (s *TransactionCategoryService) CreateCategories(c core.Context, uid int64,
|
|||||||
var allCategories []*models.TransactionCategory
|
var allCategories []*models.TransactionCategory
|
||||||
primaryCategories := categories[nil]
|
primaryCategories := categories[nil]
|
||||||
|
|
||||||
|
needPrimaryCategoryUuidCount := uint16(len(primaryCategories))
|
||||||
|
primaryCategoryUuids := s.GenerateUuids(uuid.UUID_TYPE_CATEGORY, needPrimaryCategoryUuidCount)
|
||||||
|
|
||||||
|
if len(primaryCategoryUuids) < int(needPrimaryCategoryUuidCount) {
|
||||||
|
return nil, errs.ErrSystemIsBusy
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0; i < len(primaryCategories); i++ {
|
for i := 0; i < len(primaryCategories); i++ {
|
||||||
primaryCategory := primaryCategories[i]
|
primaryCategory := primaryCategories[i]
|
||||||
primaryCategory.CategoryId = s.GenerateUuid(uuid.UUID_TYPE_CATEGORY)
|
primaryCategory.CategoryId = primaryCategoryUuids[i]
|
||||||
|
|
||||||
if primaryCategory.CategoryId < 1 {
|
|
||||||
return nil, errs.ErrSystemIsBusy
|
|
||||||
}
|
|
||||||
|
|
||||||
primaryCategory.Deleted = false
|
primaryCategory.Deleted = false
|
||||||
primaryCategory.CreatedUnixTime = time.Now().Unix()
|
primaryCategory.CreatedUnixTime = time.Now().Unix()
|
||||||
primaryCategory.UpdatedUnixTime = time.Now().Unix()
|
primaryCategory.UpdatedUnixTime = time.Now().Unix()
|
||||||
@@ -245,16 +247,17 @@ func (s *TransactionCategoryService) CreateCategories(c core.Context, uid int64,
|
|||||||
|
|
||||||
secondaryCategories := categories[primaryCategory]
|
secondaryCategories := categories[primaryCategory]
|
||||||
|
|
||||||
|
needSecondaryCategoryUuidCount := uint16(len(secondaryCategories))
|
||||||
|
secondaryCategoryUuids := s.GenerateUuids(uuid.UUID_TYPE_CATEGORY, needSecondaryCategoryUuidCount)
|
||||||
|
|
||||||
|
if len(secondaryCategoryUuids) < int(needSecondaryCategoryUuidCount) {
|
||||||
|
return nil, errs.ErrSystemIsBusy
|
||||||
|
}
|
||||||
|
|
||||||
for j := 0; j < len(secondaryCategories); j++ {
|
for j := 0; j < len(secondaryCategories); j++ {
|
||||||
secondaryCategory := secondaryCategories[j]
|
secondaryCategory := secondaryCategories[j]
|
||||||
secondaryCategory.CategoryId = s.GenerateUuid(uuid.UUID_TYPE_CATEGORY)
|
secondaryCategory.CategoryId = secondaryCategoryUuids[j]
|
||||||
|
|
||||||
if secondaryCategory.CategoryId < 1 {
|
|
||||||
return nil, errs.ErrSystemIsBusy
|
|
||||||
}
|
|
||||||
|
|
||||||
secondaryCategory.ParentCategoryId = primaryCategory.CategoryId
|
secondaryCategory.ParentCategoryId = primaryCategory.CategoryId
|
||||||
|
|
||||||
secondaryCategory.Deleted = false
|
secondaryCategory.Deleted = false
|
||||||
secondaryCategory.CreatedUnixTime = time.Now().Unix()
|
secondaryCategory.CreatedUnixTime = time.Now().Unix()
|
||||||
secondaryCategory.UpdatedUnixTime = time.Now().Unix()
|
secondaryCategory.UpdatedUnixTime = time.Now().Unix()
|
||||||
|
|||||||
@@ -525,6 +525,13 @@ func (s *TransactionService) ModifyTransaction(c core.Context, transaction *mode
|
|||||||
return errs.ErrUserIdInvalid
|
return errs.ErrUserIdInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
needTagIndexUuidCount := uint16(len(addTagIds))
|
||||||
|
tagIndexUuids := s.GenerateUuids(uuid.UUID_TYPE_TAG_INDEX, needTagIndexUuidCount)
|
||||||
|
|
||||||
|
if len(tagIndexUuids) < int(needTagIndexUuidCount) {
|
||||||
|
return errs.ErrSystemIsBusy
|
||||||
|
}
|
||||||
|
|
||||||
updateCols := make([]string, 0, 16)
|
updateCols := make([]string, 0, 16)
|
||||||
|
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
@@ -539,14 +546,8 @@ func (s *TransactionService) ModifyTransaction(c core.Context, transaction *mode
|
|||||||
transactionTagIndexes := make([]*models.TransactionTagIndex, len(addTagIds))
|
transactionTagIndexes := make([]*models.TransactionTagIndex, len(addTagIds))
|
||||||
|
|
||||||
for i := 0; i < len(addTagIds); i++ {
|
for i := 0; i < len(addTagIds); i++ {
|
||||||
tagIndexId := s.GenerateUuid(uuid.UUID_TYPE_TAG_INDEX)
|
|
||||||
|
|
||||||
if tagIndexId < 1 {
|
|
||||||
return errs.ErrSystemIsBusy
|
|
||||||
}
|
|
||||||
|
|
||||||
transactionTagIndexes[i] = &models.TransactionTagIndex{
|
transactionTagIndexes[i] = &models.TransactionTagIndex{
|
||||||
TagIndexId: tagIndexId,
|
TagIndexId: tagIndexUuids[i],
|
||||||
Uid: transaction.Uid,
|
Uid: transaction.Uid,
|
||||||
Deleted: false,
|
Deleted: false,
|
||||||
TagId: addTagIds[i],
|
TagId: addTagIds[i],
|
||||||
|
|||||||
Reference in New Issue
Block a user