improve performance

This commit is contained in:
MaysWind
2025-04-26 22:28:25 +08:00
parent 9182e8f2ef
commit 0f6b61ce6c
3 changed files with 33 additions and 32 deletions
+9 -12
View File
@@ -201,28 +201,25 @@ func (s *AccountService) CreateAccounts(c core.Context, mainAccount *models.Acco
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()
allAccounts := make([]*models.Account, len(childrenAccounts)+1)
var allInitTransactions []*models.Transaction
mainAccount.AccountId = s.GenerateUuid(uuid.UUID_TYPE_ACCOUNT)
if mainAccount.AccountId < 1 {
return errs.ErrSystemIsBusy
}
mainAccount.AccountId = accountUuids[0]
allAccounts[0] = mainAccount
if mainAccount.Type == models.ACCOUNT_TYPE_MULTI_SUB_ACCOUNTS {
for i := 0; i < len(childrenAccounts); i++ {
childAccount := childrenAccounts[i]
childAccount.AccountId = s.GenerateUuid(uuid.UUID_TYPE_ACCOUNT)
if childAccount.AccountId < 1 {
return errs.ErrSystemIsBusy
}
childAccount.AccountId = accountUuids[i+1]
childAccount.ParentAccountId = mainAccount.AccountId
childAccount.Uid = mainAccount.Uid
childAccount.Type = models.ACCOUNT_TYPE_SINGLE_ACCOUNT
+16 -13
View File
@@ -229,14 +229,16 @@ func (s *TransactionCategoryService) CreateCategories(c core.Context, uid int64,
var allCategories []*models.TransactionCategory
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++ {
primaryCategory := primaryCategories[i]
primaryCategory.CategoryId = s.GenerateUuid(uuid.UUID_TYPE_CATEGORY)
if primaryCategory.CategoryId < 1 {
return nil, errs.ErrSystemIsBusy
}
primaryCategory.CategoryId = primaryCategoryUuids[i]
primaryCategory.Deleted = false
primaryCategory.CreatedUnixTime = time.Now().Unix()
primaryCategory.UpdatedUnixTime = time.Now().Unix()
@@ -245,16 +247,17 @@ func (s *TransactionCategoryService) CreateCategories(c core.Context, uid int64,
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++ {
secondaryCategory := secondaryCategories[j]
secondaryCategory.CategoryId = s.GenerateUuid(uuid.UUID_TYPE_CATEGORY)
if secondaryCategory.CategoryId < 1 {
return nil, errs.ErrSystemIsBusy
}
secondaryCategory.CategoryId = secondaryCategoryUuids[j]
secondaryCategory.ParentCategoryId = primaryCategory.CategoryId
secondaryCategory.Deleted = false
secondaryCategory.CreatedUnixTime = time.Now().Unix()
secondaryCategory.UpdatedUnixTime = time.Now().Unix()
+8 -7
View File
@@ -525,6 +525,13 @@ func (s *TransactionService) ModifyTransaction(c core.Context, transaction *mode
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)
now := time.Now().Unix()
@@ -539,14 +546,8 @@ func (s *TransactionService) ModifyTransaction(c core.Context, transaction *mode
transactionTagIndexes := make([]*models.TransactionTagIndex, len(addTagIds))
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{
TagIndexId: tagIndexId,
TagIndexId: tagIndexUuids[i],
Uid: transaction.Uid,
Deleted: false,
TagId: addTagIds[i],