OneBot: Leantime 改造版源码(BOM/Univer 表格/AI 接管/品牌替换等)
This commit is contained in:
85
app/Core/Cache/CacheServiceProvider.php
Normal file
85
app/Core/Cache/CacheServiceProvider.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Core\Cache;
|
||||
|
||||
use Illuminate\Cache\CacheServiceProvider as LaravelCacheServiceProvider;
|
||||
use Illuminate\Cache\MemcachedConnector;
|
||||
use Illuminate\Cache\RateLimiter;
|
||||
use Symfony\Component\Cache\Adapter\Psr16Adapter;
|
||||
|
||||
class CacheServiceProvider extends LaravelCacheServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
|
||||
$this->app->singleton('cache', function ($app) {
|
||||
|
||||
// Now that we know where the instance is bing called from
|
||||
// Let's add a domain level cache.
|
||||
$domainCacheName = get_domain_key();
|
||||
|
||||
$app['config']->set('cache.stores.'.$domainCacheName, [
|
||||
'driver' => 'file',
|
||||
'path' => storage_path('framework/cache/'.$domainCacheName.'/data'),
|
||||
]);
|
||||
|
||||
// If redis is set up let's use redis as cache
|
||||
if ($app['config']['useRedis']) {
|
||||
|
||||
$app['config']->set('cache.prefix', '');
|
||||
|
||||
// Default driver just in case it is being asked for
|
||||
$app['config']->set('cache.stores.redis.driver', 'redis');
|
||||
$app['config']->set('cache.stores.redis.connection', 'cache');
|
||||
|
||||
// Only needed when using sessions with redis
|
||||
$app['config']->set('cache.stores.sessions.driver', 'redis');
|
||||
$app['config']->set('cache.stores.sessions.connection', 'sessions');
|
||||
|
||||
$app['config']->set('cache.stores.installation.driver', 'redis');
|
||||
$app['config']->set('cache.stores.installation.connection', 'installation');
|
||||
|
||||
$app['config']->set('cache.stores.'.$domainCacheName.'.driver', 'redis');
|
||||
$app['config']->set('cache.stores.'.$domainCacheName.'.connection', 'cache');
|
||||
$app['config']->set('cache.stores.'.$domainCacheName.'.prefix', ''.$domainCacheName.':');
|
||||
|
||||
}
|
||||
|
||||
$cacheManager = new \Illuminate\Cache\CacheManager($app);
|
||||
$cacheManager->setDefaultDriver($domainCacheName);
|
||||
|
||||
return $cacheManager;
|
||||
});
|
||||
|
||||
$this->app->singleton('cache.store', function ($app) {
|
||||
return $app['cache']->driver();
|
||||
});
|
||||
|
||||
$this->app->singleton('cache.psr6', function ($app) {
|
||||
return new Psr16Adapter($app['cache.store']);
|
||||
});
|
||||
|
||||
$this->app->singleton('memcached.connector', function () {
|
||||
return new MemcachedConnector;
|
||||
});
|
||||
|
||||
$this->app->singleton(RateLimiter::class, function ($app) {
|
||||
return new RateLimiter($app->make('cache')->driver(
|
||||
$app['config']->get('cache.limiter')
|
||||
));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public function provides()
|
||||
{
|
||||
return [
|
||||
'cache', 'cache.store', 'cache.psr6', RateLimiter::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
95
app/Core/Cache/Redis/RedisServiceProvider.php
Normal file
95
app/Core/Cache/Redis/RedisServiceProvider.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Leantime\Core\Cache\Redis;
|
||||
|
||||
use Illuminate\Redis\RedisManager;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class RedisServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// Ensure cluster configuration is properly set before we configure stores
|
||||
if ($this->app['config']->useCluster) {
|
||||
$this->app['config']->set('redis.client', 'phpredis');
|
||||
$this->app['config']->set('redis.cluster', 'redis');
|
||||
}
|
||||
|
||||
$this->app->singleton('redis', function ($app) {
|
||||
// Setting up three different redis stores
|
||||
// We are using a slightly different config structure and keep redis at the root level of our config
|
||||
|
||||
$cacheConfig = $app['config']['redis']['default'];
|
||||
$cacheConfig['prefix'] = 'leantime_cache:';
|
||||
|
||||
$installationConfig = $app['config']['redis']['default'];
|
||||
$installationConfig['prefix'] = 'leantime_cache:installation:';
|
||||
|
||||
$sessionsConfig = $app['config']['redis']['default'];
|
||||
$sessionsConfig['prefix'] = 'leantime_sessions:';
|
||||
|
||||
// Prepare available redis connections
|
||||
// These connections (cache, installation, sessions) can be used for sessions and cache
|
||||
if ($app['config']->useCluster) {
|
||||
// Cluster configs and prefix management works differently than regular connections
|
||||
$app['config']->set('redis.clusters.default', [$app['config']['redis']['default']]);
|
||||
$options = $app['config']['redis']['options'];
|
||||
|
||||
// The default config is not needed anymore and shouldn't be used since the connection is a cluster
|
||||
// connection and won't work in the standard config setup
|
||||
$app['config']->set('redis.default', null);
|
||||
$app['config']->set('redis.cluster', true);
|
||||
|
||||
$app['config']->set('redis.clusters.cache', array_merge(['options' => $options], [$cacheConfig]));
|
||||
$app['config']->set('redis.clusters.cache.options.prefix', $cacheConfig['prefix']);
|
||||
|
||||
$app['config']->set('redis.clusters.installation', array_merge(['options' => $options], [$installationConfig]));
|
||||
$app['config']->set('redis.clusters.installation.options.prefix', $installationConfig['prefix']);
|
||||
|
||||
$app['config']->set('redis.clusters.sessions', array_merge(['options' => $options], [$sessionsConfig]));
|
||||
$app['config']->set('redis.clusters.sessions.options.prefix', $sessionsConfig['prefix']);
|
||||
|
||||
// Set cluster specific options
|
||||
$app['config']->set('redis.options', [
|
||||
'cluster' => 'redis',
|
||||
'parameters' => ['timeout' => 1.0],
|
||||
]);
|
||||
} else {
|
||||
// Sessions live in their OWN redis database. Cache and sessions previously
|
||||
// shared db 0 (differing only by key prefix), so ANY cache flush — Laravel's
|
||||
// RedisStore::flush() issues FLUSHDB — destroyed every session and logged every
|
||||
// user out (e.g. whenever `cache:clear` ran against production). Redis Cluster
|
||||
// does not support SELECT, so isolation only applies to non-cluster setups.
|
||||
$cacheDb = (int) ($cacheConfig['database'] ?? 0);
|
||||
$sessionsConfig['database'] = (int) env('LEAN_REDIS_SESSION_DB', $cacheDb === 0 ? 1 : 0);
|
||||
|
||||
$app['config']->set('redis.cache', $cacheConfig);
|
||||
$app['config']->set('redis.installation', $installationConfig);
|
||||
$app['config']->set('redis.sessions', $sessionsConfig);
|
||||
}
|
||||
|
||||
$redisManager = new RedisManager($app, 'phpredis', $app['config']['redis']);
|
||||
|
||||
return $redisManager;
|
||||
});
|
||||
|
||||
$this->app->bind('redis.connection', function ($app) {
|
||||
return $app['redis']->connection();
|
||||
});
|
||||
}
|
||||
|
||||
public function provides()
|
||||
{
|
||||
return ['redis', 'redis.connection'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages the instance cache.
|
||||
*/
|
||||
public function checkCacheVersion(): void {}
|
||||
}
|
||||
Reference in New Issue
Block a user