-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add chat storage auto-flush mechanism
- Introduce new configuration option `--chat-flush-interval` to control chat storage cleanup - Implement periodic chat storage flushing with configurable interval (default 7 days) - Migrate chat storage from text to CSV format for better data management - Add thread-safe file handling for chat storage operations - Update root command to support new chat flush interval flag
- Loading branch information
1 parent
0947c67
commit dedd021
Showing
5 changed files
with
110 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package helpers | ||
|
||
import ( | ||
"os" | ||
"sync" | ||
"time" | ||
|
||
"github.com/aldinokemal/go-whatsapp-web-multidevice/config" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var flushMutex sync.Mutex | ||
|
||
func FlushChatCsv() error { | ||
flushMutex.Lock() | ||
defer flushMutex.Unlock() | ||
|
||
// Create an empty file (truncating any existing content) | ||
file, err := os.OpenFile(config.PathChatStorage, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
return nil | ||
} | ||
|
||
// StartAutoFlushChatStorage starts a goroutine that periodically flushes the chat storage | ||
func StartAutoFlushChatStorage() { | ||
interval := time.Duration(config.AppChatFlushIntervalDays) * 24 * time.Hour | ||
|
||
go func() { | ||
ticker := time.NewTicker(interval) | ||
defer ticker.Stop() | ||
|
||
for range ticker.C { | ||
if err := FlushChatCsv(); err != nil { | ||
logrus.Errorf("Error flushing chat storage: %v", err) | ||
} else { | ||
logrus.Info("Successfully flushed chat storage") | ||
} | ||
} | ||
}() | ||
|
||
logrus.Infof("Auto flush for chat storage started (your account chat still safe). Will flush every %d days", config.AppChatFlushIntervalDays) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The new version is 5.1.1