⚡ Fix the RandString method cause the lag
This commit is contained in:
parent
f32803acf4
commit
e7f6637398
66
.idea/workspace.xml
generated
66
.idea/workspace.xml
generated
@ -4,8 +4,10 @@
|
|||||||
<option name="autoReloadType" value="ALL" />
|
<option name="autoReloadType" value="ALL" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":bug: Fix sql statement">
|
<list default="true" id="18dd0d68-b4b8-40db-9734-9119b5c848bd" name="更改" comment=":bug: Fix doesn't get has lifecycle settings buckets correctly">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/pkg/internal/services/attachments.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/attachments.go" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/pkg/internal/services/random_id.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/random_id.go" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/pkg/internal/services/recycler.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/recycler.go" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pkg/internal/services/recycler.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/recycler.go" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
@ -36,33 +38,33 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"DefaultGoTemplateProperty": "Go File",
|
"DefaultGoTemplateProperty": "Go File",
|
||||||
"Go Build.Backend.executor": "Debug",
|
"Go Build.Backend.executor": "Debug",
|
||||||
"Go 构建.Backend.executor": "Run",
|
"Go 构建.Backend.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
"RunOnceActivity.go.formatter.settings.were.checked": "true",
|
||||||
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
"RunOnceActivity.go.migrated.go.modules.settings": "true",
|
||||||
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
|
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
|
||||||
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
"RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
|
||||||
"git-widget-placeholder": "master",
|
"git-widget-placeholder": "master",
|
||||||
"go.import.settings.migrated": "true",
|
"go.import.settings.migrated": "true",
|
||||||
"go.sdk.automatically.set": "true",
|
"go.sdk.automatically.set": "true",
|
||||||
"last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hydrogen/Paperclip/pkg/internal/grpc",
|
"last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hydrogen/Paperclip/pkg/internal/grpc",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"run.code.analysis.last.selected.profile": "pProject Default",
|
"run.code.analysis.last.selected.profile": "pProject Default",
|
||||||
"settings.editor.selected.configurable": "preferences.pluginManager",
|
"settings.editor.selected.configurable": "preferences.pluginManager",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
},
|
},
|
||||||
"keyToStringList": {
|
"keyToStringList": {
|
||||||
"DatabaseDriversLRU": [
|
"DatabaseDriversLRU": [
|
||||||
"postgresql"
|
"postgresql"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="CopyFile.RECENT_KEYS">
|
<key name="CopyFile.RECENT_KEYS">
|
||||||
<recent name="$PROJECT_DIR$/pkg/internal/grpc" />
|
<recent name="$PROJECT_DIR$/pkg/internal/grpc" />
|
||||||
@ -131,7 +133,8 @@
|
|||||||
<MESSAGE value=":bug: Fix migration issue on pools" />
|
<MESSAGE value=":bug: Fix migration issue on pools" />
|
||||||
<MESSAGE value=":bug: Fix schedule deletion will delete referenced file" />
|
<MESSAGE value=":bug: Fix schedule deletion will delete referenced file" />
|
||||||
<MESSAGE value=":bug: Fix sql statement" />
|
<MESSAGE value=":bug: Fix sql statement" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix sql statement" />
|
<MESSAGE value=":bug: Fix doesn't get has lifecycle settings buckets correctly" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix doesn't get has lifecycle settings buckets correctly" />
|
||||||
</component>
|
</component>
|
||||||
<component name="VgoProject">
|
<component name="VgoProject">
|
||||||
<settings-migrated>true</settings-migrated>
|
<settings-migrated>true</settings-migrated>
|
||||||
@ -140,14 +143,9 @@
|
|||||||
<breakpoint-manager>
|
<breakpoint-manager>
|
||||||
<breakpoints>
|
<breakpoints>
|
||||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
||||||
<url>file://$PROJECT_DIR$/pkg/internal/services/recycler.go</url>
|
<url>file://$PROJECT_DIR$/pkg/internal/services/attachments.go</url>
|
||||||
<line>45</line>
|
<line>62</line>
|
||||||
<option name="timeStamp" value="4" />
|
<option name="timeStamp" value="3" />
|
||||||
</line-breakpoint>
|
|
||||||
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
|
|
||||||
<url>file://$PROJECT_DIR$/pkg/internal/services/recycler.go</url>
|
|
||||||
<line>40</line>
|
|
||||||
<option name="timeStamp" value="5" />
|
|
||||||
</line-breakpoint>
|
</line-breakpoint>
|
||||||
</breakpoints>
|
</breakpoints>
|
||||||
</breakpoint-manager>
|
</breakpoint-manager>
|
||||||
|
@ -60,8 +60,8 @@ func CacheAttachment(id uint, item models.Attachment) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewAttachmentMetadata(tx *gorm.DB, user models.Account, file *multipart.FileHeader, attachment models.Attachment) (models.Attachment, error) {
|
func NewAttachmentMetadata(tx *gorm.DB, user models.Account, file *multipart.FileHeader, attachment models.Attachment) (models.Attachment, error) {
|
||||||
attachment.Rid = RandString(16)
|
|
||||||
attachment.Uuid = uuid.NewString()
|
attachment.Uuid = uuid.NewString()
|
||||||
|
attachment.Rid = RandString(16)
|
||||||
attachment.Size = file.Size
|
attachment.Size = file.Size
|
||||||
attachment.Name = file.Filename
|
attachment.Name = file.Filename
|
||||||
attachment.AccountID = user.ID
|
attachment.AccountID = user.ID
|
||||||
|
@ -2,30 +2,14 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||||
const (
|
|
||||||
letterIdxBits = 6
|
|
||||||
letterIdxMask = 1<<letterIdxBits - 1
|
|
||||||
letterIdxMax = 63 / letterIdxBits
|
|
||||||
)
|
|
||||||
|
|
||||||
func RandString(length int) string {
|
func RandString(length int) string {
|
||||||
builder := strings.Builder{}
|
builder := make([]rune, length)
|
||||||
builder.Grow(length)
|
for i := range builder {
|
||||||
for idx, cache, remain := length-1, rand.Int63(), letterIdxMax; idx >= 0; {
|
builder[i] = letters[rand.Intn(len(letters))]
|
||||||
if remain == 0 {
|
|
||||||
cache, remain = rand.Int63(), letterIdxMax
|
|
||||||
}
|
|
||||||
if idx := int(cache & letterIdxMask); idx < len(letterBytes) {
|
|
||||||
builder.WriteByte(letterBytes[idx])
|
|
||||||
idx--
|
|
||||||
}
|
|
||||||
cache >>= letterIdxBits
|
|
||||||
remain--
|
|
||||||
}
|
}
|
||||||
|
return string(builder)
|
||||||
return builder.String()
|
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,8 @@ func RunMarkDeletionTask() {
|
|||||||
for _, pool := range pendingPools {
|
for _, pool := range pendingPools {
|
||||||
lifecycle := fmt.Sprintf("%d seconds", *pool.Config.Data().ExistLifecycle)
|
lifecycle := fmt.Sprintf("%d seconds", *pool.Config.Data().ExistLifecycle)
|
||||||
tx := database.C.
|
tx := database.C.
|
||||||
Where("pool_id = ? AND created_at < NOW() - INTERVAL ?", pool.ID, lifecycle).
|
Where("pool_id = ?", pool.ID).
|
||||||
|
Where("created_at < NOW() - INTERVAL ?", lifecycle).
|
||||||
Updates(&models.Attachment{CleanedAt: lo.ToPtr(time.Now())})
|
Updates(&models.Attachment{CleanedAt: lo.ToPtr(time.Now())})
|
||||||
log.Info().
|
log.Info().
|
||||||
Str("pool", pool.Alias).
|
Str("pool", pool.Alias).
|
||||||
|
Loading…
Reference in New Issue
Block a user