mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-10-31 08:29:33 +08:00 
			
		
		
		
	* Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * feat: add code lint * feat: add code lint * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * Script Refactoring * feat: code format * Script Refactoring * Script Refactoring * Script Refactoring * Adjust MinIO configuration settings * Adjust configuration settings * Adjust configuration settings * refactor: config change. * refactor: webhooks update. * Adjust configuration settings * refactor: webhooks update. * Adjust configuration settings * Adjust configuration settings * Adjust configuration settings * feat: s3 api addr * refactor: webhooks update. * Adjust configuration settings * Adjust configuration settings * Adjust configuration settings * Adjust configuration settings * Adjust configuration settings * Adjust configuration settings * Adjust configuration settings * refactor: webhooks update. * refactor: kafka update. * Simplify the Docker Compose configuration, remove unnecessary environment variables, and eliminate the gateway service. * refactor: kafka update. * refactor: kafka update. * Simplify the Docker Compose configuration, remove unnecessary environment variables, and eliminate the gateway service. * Simplify the Docker Compose configuration, remove unnecessary environment variables, and eliminate the gateway service. * Windows can compile and run. * Windows can compile and run. * refactor: kafka update. * feat: msg cache split * refactor: webhooks update * refactor: webhooks update * refactor: friends update * refactor: group update * refactor: third update * refactor: api update * refactor: crontab update * refactor: msggateway update * mage * mage * refactor: all module update. * check * refactor: all module update. * load config * load config * load config * load config * refactor: all module update. * refactor: all module update. * refactor: all module update. * refactor: all module update. * refactor: all module update. * Optimize Docker configuration and script. * refactor: all module update. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * refactor: all module update. * Optimize Docker configuration and script. * refactor: all module update. * refactor: all module update. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * update tools * update tools * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * update protocol * Optimize Docker configuration and script. * Optimize Docker configuration and script. * refactor: all module update. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * Optimize Docker configuration and script. * refactor: api remove token auth by redis directly. * Code Refactoring * refactor: websocket auth change to call rpc of auth. * refactor: kick online user and remove token change to call auth rpc. * refactor: kick online user and remove token change to call auth rpc. * refactor: remove msggateway redis. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor webhook * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor webhook * refactor: cmd update. * refactor: cmd update. * fix: runtime: goroutine stack exceeds * refactor: cmd update. * refactor notification * refactor notification * refactor * refactor: cmd update. * refactor: cmd update. * refactor * refactor * refactor * protojson * protojson * protojson * go mod * wrapperspb * refactor: cmd update. * refactor: cmd update. * refactor: cmd update. * refactor: context update. * refactor: websocket update info. * refactor: websocket update info. * refactor: websocket update info. * refactor: websocket update info. * refactor: api name change. * refactor: debug info. * refactor: debug info. * refactor: debug info. * fix: update file * refactor * refactor * refactor: debug info. * refactor: debug info. * refactor: debug info. * refactor: debug info. * refactor: debug info. * refactor: debug info. * fix: callback update. * fix: callback update. * refactor * fix: update message. * fix: msg cache timeout. * refactor * refactor * fix: push update. * fix: push update. * fix: push update. * fix: push update. * fix: push update. * fix: push update. * fix: push update. * fix: websocket handle error remove when upgrade error. --------- Co-authored-by: skiffer-git <44203734@qq.com> Co-authored-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> Co-authored-by: withchao <993506633@qq.com>
		
			
				
	
	
		
			208 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			208 lines
		
	
	
		
			6.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright © 2023 OpenIM. All rights reserved.
 | |
| //
 | |
| // Licensed under the Apache License, Version 2.0 (the "License");
 | |
| // you may not use this file except in compliance with the License.
 | |
| // You may obtain a copy of the License at
 | |
| //
 | |
| //     http://www.apache.org/licenses/LICENSE-2.0
 | |
| //
 | |
| // Unless required by applicable law or agreed to in writing, software
 | |
| // distributed under the License is distributed on an "AS IS" BASIS,
 | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | |
| // See the License for the specific language governing permissions and
 | |
| // limitations under the License.
 | |
| 
 | |
| package cache
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"github.com/openimsdk/tools/s3/cont"
 | |
| 	"github.com/openimsdk/tools/s3/minio"
 | |
| 	"strconv"
 | |
| 	"time"
 | |
| 
 | |
| 	"github.com/dtm-labs/rockscache"
 | |
| 	relationtb "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
 | |
| 	"github.com/openimsdk/tools/s3"
 | |
| 	"github.com/redis/go-redis/v9"
 | |
| )
 | |
| 
 | |
| type ObjectCache interface {
 | |
| 	metaCache
 | |
| 	GetName(ctx context.Context, engine string, name string) (*relationtb.ObjectModel, error)
 | |
| 	DelObjectName(engine string, names ...string) ObjectCache
 | |
| }
 | |
| 
 | |
| func NewObjectCacheRedis(rdb redis.UniversalClient, objDB relationtb.ObjectInfoModelInterface) ObjectCache {
 | |
| 	rcClient := rockscache.NewClient(rdb, rockscache.NewDefaultOptions())
 | |
| 	return &objectCacheRedis{
 | |
| 		rcClient:   rcClient,
 | |
| 		expireTime: time.Hour * 12,
 | |
| 		objDB:      objDB,
 | |
| 		metaCache:  NewMetaCacheRedis(rcClient),
 | |
| 	}
 | |
| }
 | |
| 
 | |
| type objectCacheRedis struct {
 | |
| 	metaCache
 | |
| 	objDB      relationtb.ObjectInfoModelInterface
 | |
| 	rcClient   *rockscache.Client
 | |
| 	expireTime time.Duration
 | |
| }
 | |
| 
 | |
| func (g *objectCacheRedis) NewCache() ObjectCache {
 | |
| 	return &objectCacheRedis{
 | |
| 		rcClient:   g.rcClient,
 | |
| 		expireTime: g.expireTime,
 | |
| 		objDB:      g.objDB,
 | |
| 		metaCache:  NewMetaCacheRedis(g.rcClient, g.metaCache.GetPreDelKeys()...),
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (g *objectCacheRedis) DelObjectName(engine string, names ...string) ObjectCache {
 | |
| 	objectCache := g.NewCache()
 | |
| 	keys := make([]string, 0, len(names))
 | |
| 	for _, name := range names {
 | |
| 		keys = append(keys, g.getObjectKey(name, engine))
 | |
| 	}
 | |
| 	objectCache.AddKeys(keys...)
 | |
| 	return objectCache
 | |
| }
 | |
| 
 | |
| func (g *objectCacheRedis) getObjectKey(engine string, name string) string {
 | |
| 	return "OBJECT:" + engine + ":" + name
 | |
| }
 | |
| 
 | |
| func (g *objectCacheRedis) GetName(ctx context.Context, engine string, name string) (*relationtb.ObjectModel, error) {
 | |
| 	return getCache(ctx, g.rcClient, g.getObjectKey(name, engine), g.expireTime, func(ctx context.Context) (*relationtb.ObjectModel, error) {
 | |
| 		return g.objDB.Take(ctx, engine, name)
 | |
| 	})
 | |
| }
 | |
| 
 | |
| type S3Cache interface {
 | |
| 	metaCache
 | |
| 	GetKey(ctx context.Context, engine string, key string) (*s3.ObjectInfo, error)
 | |
| 	DelS3Key(engine string, keys ...string) S3Cache
 | |
| }
 | |
| 
 | |
| func NewS3Cache(rdb redis.UniversalClient, s3 s3.Interface) cont.S3Cache {
 | |
| 	rcClient := rockscache.NewClient(rdb, rockscache.NewDefaultOptions())
 | |
| 	return &s3CacheRedis{
 | |
| 		rcClient:   rcClient,
 | |
| 		expireTime: time.Hour * 12,
 | |
| 		s3:         s3,
 | |
| 		metaCache:  NewMetaCacheRedis(rcClient),
 | |
| 	}
 | |
| }
 | |
| 
 | |
| type s3CacheRedis struct {
 | |
| 	metaCache
 | |
| 	s3         s3.Interface
 | |
| 	rcClient   *rockscache.Client
 | |
| 	expireTime time.Duration
 | |
| }
 | |
| 
 | |
| func (g *s3CacheRedis) newCache() *s3CacheRedis {
 | |
| 	return &s3CacheRedis{
 | |
| 		rcClient:   g.rcClient,
 | |
| 		expireTime: g.expireTime,
 | |
| 		s3:         g.s3,
 | |
| 		metaCache:  NewMetaCacheRedis(g.rcClient, g.metaCache.GetPreDelKeys()...),
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (g *s3CacheRedis) DelS3Key(ctx context.Context, engine string, keys ...string) error {
 | |
| 	s3cache := g.newCache()
 | |
| 	ks := make([]string, 0, len(keys))
 | |
| 	for _, key := range keys {
 | |
| 		ks = append(ks, g.getS3Key(engine, key))
 | |
| 	}
 | |
| 	s3cache.AddKeys(ks...)
 | |
| 	return s3cache.ExecDel(ctx)
 | |
| }
 | |
| 
 | |
| func (g *s3CacheRedis) getS3Key(engine string, name string) string {
 | |
| 	return "S3:" + engine + ":" + name
 | |
| }
 | |
| 
 | |
| func (g *s3CacheRedis) GetKey(ctx context.Context, engine string, name string) (*s3.ObjectInfo, error) {
 | |
| 	return getCache(ctx, g.rcClient, g.getS3Key(engine, name), g.expireTime, func(ctx context.Context) (*s3.ObjectInfo, error) {
 | |
| 		return g.s3.StatObject(ctx, name)
 | |
| 	})
 | |
| }
 | |
| 
 | |
| type MinioCache interface {
 | |
| 	metaCache
 | |
| 	GetImageObjectKeyInfo(ctx context.Context, key string, fn func(ctx context.Context) (*MinioImageInfo, error)) (*MinioImageInfo, error)
 | |
| 	GetThumbnailKey(ctx context.Context, key string, format string, width int, height int, minioCache func(ctx context.Context) (string, error)) (string, error)
 | |
| 	DelObjectImageInfoKey(keys ...string) MinioCache
 | |
| 	DelImageThumbnailKey(key string, format string, width int, height int) MinioCache
 | |
| }
 | |
| 
 | |
| func NewMinioCache(rdb redis.UniversalClient) minio.Cache {
 | |
| 	rcClient := rockscache.NewClient(rdb, rockscache.NewDefaultOptions())
 | |
| 	return &minioCacheRedis{
 | |
| 		rcClient:   rcClient,
 | |
| 		expireTime: time.Hour * 24 * 7,
 | |
| 		metaCache:  NewMetaCacheRedis(rcClient),
 | |
| 	}
 | |
| }
 | |
| 
 | |
| type minioCacheRedis struct {
 | |
| 	metaCache
 | |
| 	rcClient   *rockscache.Client
 | |
| 	expireTime time.Duration
 | |
| }
 | |
| 
 | |
| func (g *minioCacheRedis) newCache() *minioCacheRedis {
 | |
| 	return &minioCacheRedis{
 | |
| 		rcClient:   g.rcClient,
 | |
| 		expireTime: g.expireTime,
 | |
| 		metaCache:  NewMetaCacheRedis(g.rcClient, g.metaCache.GetPreDelKeys()...),
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func (g *minioCacheRedis) DelObjectImageInfoKey(ctx context.Context, keys ...string) error {
 | |
| 	s3cache := g.newCache()
 | |
| 	ks := make([]string, 0, len(keys))
 | |
| 	for _, key := range keys {
 | |
| 		ks = append(ks, g.getObjectImageInfoKey(key))
 | |
| 	}
 | |
| 	s3cache.AddKeys(ks...)
 | |
| 	return s3cache.ExecDel(ctx)
 | |
| }
 | |
| 
 | |
| func (g *minioCacheRedis) DelImageThumbnailKey(ctx context.Context, key string, format string, width int, height int) error {
 | |
| 	s3cache := g.newCache()
 | |
| 	s3cache.AddKeys(g.getMinioImageThumbnailKey(key, format, width, height))
 | |
| 	return s3cache.ExecDel(ctx)
 | |
| }
 | |
| 
 | |
| func (g *minioCacheRedis) getObjectImageInfoKey(key string) string {
 | |
| 	return "MINIO:IMAGE:" + key
 | |
| }
 | |
| 
 | |
| func (g *minioCacheRedis) getMinioImageThumbnailKey(key string, format string, width int, height int) string {
 | |
| 	return "MINIO:THUMBNAIL:" + format + ":w" + strconv.Itoa(width) + ":h" + strconv.Itoa(height) + ":" + key
 | |
| }
 | |
| 
 | |
| func (g *minioCacheRedis) GetImageObjectKeyInfo(ctx context.Context, key string, fn func(ctx context.Context) (*minio.ImageInfo, error)) (*minio.ImageInfo, error) {
 | |
| 	info, err := getCache(ctx, g.rcClient, g.getObjectImageInfoKey(key), g.expireTime, fn)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return info, nil
 | |
| }
 | |
| 
 | |
| func (g *minioCacheRedis) GetThumbnailKey(ctx context.Context, key string, format string, width int, height int, minioCache func(ctx context.Context) (string, error)) (string, error) {
 | |
| 	return getCache(ctx, g.rcClient, g.getMinioImageThumbnailKey(key, format, width, height), g.expireTime, minioCache)
 | |
| }
 | |
| 
 | |
| type MinioImageInfo struct {
 | |
| 	IsImg  bool   `json:"isImg"`
 | |
| 	Width  int    `json:"width"`
 | |
| 	Height int    `json:"height"`
 | |
| 	Format string `json:"format"`
 | |
| 	Etag   string `json:"etag"`
 | |
| }
 |