mirror of
https://github.com/glowingblue/flarum-ext-redis-setup.git
synced 2026-03-22 15:07:53 +01:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d59ebfa684 | ||
|
|
b03ca35d54 | ||
|
|
4c7a5d377d | ||
|
|
6545bfdffc | ||
|
|
2f2cce1abe | ||
|
|
78082dc842 | ||
|
|
e02001333b | ||
|
|
44fa68c278 | ||
|
|
139d687e1b | ||
|
|
9061552db9 | ||
|
|
eab24f9adc | ||
|
|
94049c5183 | ||
|
|
96af9b58f6 | ||
|
|
69c73e2397 | ||
|
|
c2ddd30cd7 |
11
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
11
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
**Resolves**
|
||||||
|
<!-- include a link to the issue -->
|
||||||
|
|
||||||
|
**Changes proposed in this pull request:**
|
||||||
|
<!-- mention the pages and/or components which have been impacted -->
|
||||||
|
|
||||||
|
**Reviewers should focus on:**
|
||||||
|
<!-- ask for feedback on specific changes you are unsure about -->
|
||||||
|
|
||||||
|
**Screenshot**
|
||||||
|
<!-- include an image of the most relevant user-facing change, if any -->
|
||||||
13
.github/workflows/backend.yml
vendored
Normal file
13
.github/workflows/backend.yml
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
name: GB Redis Setup PHP
|
||||||
|
|
||||||
|
on: [workflow_dispatch, push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
run:
|
||||||
|
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@1.x
|
||||||
|
with:
|
||||||
|
enable_backend_testing: false
|
||||||
|
enable_phpstan: true
|
||||||
|
php_versions: '["8.1", "8.2", "8.3", "8.4"]'
|
||||||
|
|
||||||
|
backend_directory: .
|
||||||
19
.github/workflows/frontend.yml
vendored
Normal file
19
.github/workflows/frontend.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
name: GB Redis Setup JS
|
||||||
|
|
||||||
|
on: [workflow_dispatch, push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
run:
|
||||||
|
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@1.x
|
||||||
|
with:
|
||||||
|
enable_bundlewatch: false
|
||||||
|
enable_prettier: true
|
||||||
|
enable_typescript: false
|
||||||
|
|
||||||
|
frontend_directory: ./js
|
||||||
|
backend_directory: .
|
||||||
|
js_package_manager: yarn
|
||||||
|
main_git_branch: master
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
|
||||||
91
.github/workflows/js.yml
vendored
91
.github/workflows/js.yml
vendored
@@ -1,91 +0,0 @@
|
|||||||
name: JS
|
|
||||||
|
|
||||||
on: [workflow_dispatch, push, pull_request]
|
|
||||||
|
|
||||||
env:
|
|
||||||
NODE_VERSION: 16
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
prettier:
|
|
||||||
name: Prettier
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Check out code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set up Node
|
|
||||||
uses: actions/setup-node@v2
|
|
||||||
with:
|
|
||||||
node-version: ${{ env.NODE_VERSION }}
|
|
||||||
cache: 'yarn'
|
|
||||||
cache-dependency-path: js/yarn.lock
|
|
||||||
|
|
||||||
- name: Install JS dependencies
|
|
||||||
run: yarn install --immutable
|
|
||||||
working-directory: ./js
|
|
||||||
|
|
||||||
- name: Check JS formatting
|
|
||||||
run: yarn run format-check
|
|
||||||
working-directory: ./js
|
|
||||||
|
|
||||||
build-prod:
|
|
||||||
name: Build and commit
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [prettier]
|
|
||||||
|
|
||||||
# Only commit JS on push to master branch
|
|
||||||
# Remember to change in `build-test` job too
|
|
||||||
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Check out code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set up Node
|
|
||||||
uses: actions/setup-node@v2
|
|
||||||
with:
|
|
||||||
node-version: ${{ env.NODE_VERSION }}
|
|
||||||
cache: 'yarn'
|
|
||||||
cache-dependency-path: js/yarn.lock
|
|
||||||
|
|
||||||
# Our action will install node, npm and yarn, cd into `./js`, run `yarn run build` (and
|
|
||||||
# `yarn run build-typings` if desired), then commit and upload any changes
|
|
||||||
- name: Build production JS
|
|
||||||
uses: flarum/action-build@2
|
|
||||||
with:
|
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
build_script: build
|
|
||||||
package_manager: yarn
|
|
||||||
# typings_script: build-typings
|
|
||||||
|
|
||||||
build-test:
|
|
||||||
name: Test build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs: [prettier]
|
|
||||||
|
|
||||||
# Inverse check of `build-prod`
|
|
||||||
# Remember to change in `build-prod` job too
|
|
||||||
if: github.ref != 'refs/heads/master' || github.event_name != 'push'
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Check out code
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set up Node
|
|
||||||
uses: actions/setup-node@v2
|
|
||||||
with:
|
|
||||||
node-version: ${{ env.NODE_VERSION }}
|
|
||||||
cache: 'yarn'
|
|
||||||
cache-dependency-path: js/yarn.lock
|
|
||||||
|
|
||||||
# Our action will install node, npm and yarn, cd into `./js`, run `yarn run build` (and
|
|
||||||
# `yarn run build-typings` if desired). It will NOT commit and upload.
|
|
||||||
- name: Build production JS
|
|
||||||
uses: flarum/action-build@2
|
|
||||||
with:
|
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
build_script: build
|
|
||||||
package_manager: yarn
|
|
||||||
# typings_script: build-typings
|
|
||||||
do_not_commit: true
|
|
||||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -65,6 +65,7 @@
|
|||||||
"bmewburn.vscode-intelephense-client",
|
"bmewburn.vscode-intelephense-client",
|
||||||
"dbaeumer.vscode-eslint",
|
"dbaeumer.vscode-eslint",
|
||||||
"esbenp.prettier-vscode",
|
"esbenp.prettier-vscode",
|
||||||
"felixfbecker.php-debug"
|
"xdebug.php-debug",
|
||||||
|
"firefox-devtools.vscode-firefox-debug"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,9 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://glowingblue.com",
|
"homepage": "https://glowingblue.com",
|
||||||
"require": {
|
"require": {
|
||||||
"flarum/core": "^1.0.4",
|
"php": "^8.1",
|
||||||
"blomstra/flarum-redis": "^0.4.0"
|
"flarum/core": "^1.8.5",
|
||||||
|
"fof/redis": "^1.0"
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
@@ -52,11 +53,22 @@
|
|||||||
"color": "#fff"
|
"color": "#fff"
|
||||||
},
|
},
|
||||||
"optional-dependencies": [
|
"optional-dependencies": [
|
||||||
"blomstra/horizon"
|
"fof/horizon"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"extiverse": {
|
"extiverse": {
|
||||||
"discuss": "https://discuss.flarum.org/d/27455"
|
"discuss": "https://discuss.flarum.org/d/27455"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"flarum/phpstan": "*",
|
||||||
|
"fof/horizon": "^1.0"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"analyse:phpstan": "phpstan analyse",
|
||||||
|
"clear-cache:phpstan": "phpstan clear-result-cache"
|
||||||
|
},
|
||||||
|
"scripts-descriptions": {
|
||||||
|
"analyse:phpstan": "Run static analysis"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
js/dist/admin.js
vendored
2
js/dist/admin.js
vendored
@@ -1,2 +1,2 @@
|
|||||||
module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=3)}([function(e,t){e.exports=flarum.core.compat["admin/app"]},function(e,t){e.exports=flarum.core.compat["common/extend"]},function(e,t){e.exports=flarum.core.compat["admin/components/StatusWidget"]},function(e,t,r){"use strict";r.r(t);var n=r(0),o=r.n(n),a=r(1),i=r(2),l=r.n(i),u="glowingblue-redis-setup";function s(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return c(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return c(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var f=o.a.translator.trans.bind(o.a.translator),d=u+".admin.settings";o.a.initializers.add(u,(function(){o.a.extensionData.for(u).registerSetting({setting:"glowingblue-redis.enableCache",type:"boolean",label:f(d+".enable_cache")}).registerSetting({setting:"glowingblue-redis.redisSessions",type:"boolean",label:f(d+".enable_redis_sessions")}).registerSetting({setting:"glowingblue-redis.enableQueue",type:"boolean",label:f(d+".enable_queue")}),o.a.initializers.has("blomstra/horizon")&&o.a.extensionData.for(u).registerSetting({setting:"glowingblue-redis.horizonConfig",type:"textarea",label:f(d+".horizon_config"),help:f(d+".horizon_help_text")}),Object(a.extend)(l.a.prototype,"items",(function(e){var t=o.a.data.blomstraQueuesLoad;if(void 0!==t)for(var r,n=s(o.a.data.blomstraQueuesSeen);!(r=n()).done;){var a=r.value,i=t[a]||null;e.add("blomstra-queue-size-"+a,[m("strong",null,"Queue ",a),m("br",null),i||"0"])}}))}))}]);
|
(()=>{var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};(()=>{"use strict";e.r(t);const r=flarum.core.compat["admin/app"];var n=e.n(r);const o=flarum.core.compat["common/extend"],a=flarum.core.compat["admin/components/StatusWidget"];var i=e.n(a),l="glowingblue-redis-setup";function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var u=n().translator.trans.bind(n().translator),d=l+".admin.settings";n().initializers.add(l,(function(){n().extensionData.for(l).registerSetting({setting:"glowingblue-redis.enableCache",type:"boolean",label:u(d+".enable_cache")}).registerSetting({setting:"glowingblue-redis.redisSessions",type:"boolean",label:u(d+".enable_redis_sessions")}).registerSetting({setting:"glowingblue-redis.enableQueue",type:"boolean",label:u(d+".enable_queue")}),n().initializers.has("fof/horizon")&&n().extensionData.for(l).registerSetting({setting:"glowingblue-redis.horizonConfig",type:"textarea",label:u(d+".horizon_config"),help:u(d+".horizon_help_text")}),(0,o.extend)(i().prototype,"items",(function(e){var t=n().data.fofQueuesLoad;if(void 0!==t)for(var r,o=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(n().data.fofQueuesSeen);!(r=o()).done;){var a=r.value,i=t[a]||null;e.add("fof-queue-size-"+a,[m("strong",null,"Queue ",a),m("br",null),i||"0"])}}))}))})(),module.exports=t})();
|
||||||
//# sourceMappingURL=admin.js.map
|
//# sourceMappingURL=admin.js.map
|
||||||
2
js/dist/admin.js.map
vendored
2
js/dist/admin.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -4,13 +4,13 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"prettier": "@glowingblue-dev/prettier-config",
|
"prettier": "@glowingblue-dev/prettier-config",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"flarum-webpack-config": "^1.0.0",
|
"flarum-webpack-config": "^2.0.0",
|
||||||
"webpack": "^4.26.0",
|
"webpack": "^5.72.0",
|
||||||
"webpack-cli": "^4.9.2"
|
"webpack-cli": "^5.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@glowingblue-dev/prettier-config": "^1.0.0",
|
"@glowingblue-dev/prettier-config": "^1.0.0",
|
||||||
"prettier": "^2.6.1"
|
"prettier": "^3.5.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "webpack --mode development --watch",
|
"dev": "webpack --mode development --watch",
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ app.initializers.add(slug, () => {
|
|||||||
label: t(`${prfx}.enable_queue`),
|
label: t(`${prfx}.enable_queue`),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (app.initializers.has('blomstra/horizon')) {
|
if (app.initializers.has('fof/horizon')) {
|
||||||
app.extensionData.for(slug).registerSetting({
|
app.extensionData.for(slug).registerSetting({
|
||||||
setting: 'glowingblue-redis.horizonConfig',
|
setting: 'glowingblue-redis.horizonConfig',
|
||||||
type: 'textarea',
|
type: 'textarea',
|
||||||
@@ -46,15 +46,16 @@ app.initializers.add(slug, () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extend(StatusWidget.prototype, 'items', (items) => {
|
extend(StatusWidget.prototype, 'items', (items) => {
|
||||||
const loads = app.data.blomstraQueuesLoad;
|
const loads = app.data.fofQueuesLoad;
|
||||||
|
|
||||||
if (loads === undefined) {
|
if (loads === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let queue of app.data.blomstraQueuesSeen) {
|
// @ts-ignore
|
||||||
|
for (let queue of app.data.fofQueuesSeen) {
|
||||||
const load = loads[queue] || null;
|
const load = loads[queue] || null;
|
||||||
items.add('blomstra-queue-size-' + queue, [
|
items.add('fof-queue-size-' + queue, [
|
||||||
<strong>Queue {queue}</strong>,
|
<strong>Queue {queue}</strong>,
|
||||||
<br />,
|
<br />,
|
||||||
load || '0',
|
load || '0',
|
||||||
17
js/tsconfig.json
Normal file
17
js/tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
// Use Flarum's tsconfig as a starting point
|
||||||
|
"extends": "flarum-tsconfig",
|
||||||
|
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
|
||||||
|
// and also tells your Typescript server to read core's global typings for
|
||||||
|
// access to `dayjs` and `$` in the global namespace.
|
||||||
|
"include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*"],
|
||||||
|
"compilerOptions": {
|
||||||
|
// This will output typings to `dist-typings`
|
||||||
|
"declarationDir": "./dist-typings",
|
||||||
|
"baseUrl": ".",
|
||||||
|
"paths": {
|
||||||
|
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
4586
js/yarn.lock
4586
js/yarn.lock
File diff suppressed because it is too large
Load Diff
13
phpstan.neon
Normal file
13
phpstan.neon
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
includes:
|
||||||
|
- vendor/flarum/phpstan/extension.neon
|
||||||
|
|
||||||
|
parameters:
|
||||||
|
# The level will be increased in Flarum 2.0
|
||||||
|
level: 5
|
||||||
|
paths:
|
||||||
|
- extend.php
|
||||||
|
- src
|
||||||
|
excludePaths:
|
||||||
|
- *.blade.php
|
||||||
|
checkMissingIterableValueType: false
|
||||||
|
databaseMigrationsPath: ['migrations']
|
||||||
@@ -6,4 +6,4 @@ glowingblue-redis-setup:
|
|||||||
Enable Redis sessions (all users will be logged out after changing this setting)
|
Enable Redis sessions (all users will be logged out after changing this setting)
|
||||||
enable_queue: Enable Redis queue
|
enable_queue: Enable Redis queue
|
||||||
horizon_config: "Horizon config (format: JSON)."
|
horizon_config: "Horizon config (format: JSON)."
|
||||||
horizon_help_text: This will be passed to <code>(new \Blomstra\Horizon\Extend\Horizon)->config(...))</code>
|
horizon_help_text: This will be passed to <code>(new \FoF\Horizon\Extend\Horizon)->config(...))</code>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
namespace GlowingBlue\RedisSetup\Extend;
|
namespace GlowingBlue\RedisSetup\Extend;
|
||||||
|
|
||||||
use Blomstra\Horizon\Extend\Horizon;
|
use FoF\Horizon\Extend\Horizon;
|
||||||
use Flarum\Extend\ExtenderInterface;
|
use Flarum\Extend\ExtenderInterface;
|
||||||
use Flarum\Extension\Extension;
|
use Flarum\Extension\Extension;
|
||||||
use Flarum\Extension\ExtensionManager;
|
use Flarum\Extension\ExtensionManager;
|
||||||
@@ -25,7 +25,7 @@ class ConfigureHorizon implements ExtenderInterface
|
|||||||
{
|
{
|
||||||
$extensions = resolve(ExtensionManager::class);
|
$extensions = resolve(ExtensionManager::class);
|
||||||
|
|
||||||
if (!$extensions->isEnabled('blomstra-horizon') || !class_exists(Horizon::class)) {
|
if (!$extensions->isEnabled('fof-horizon') || !class_exists(Horizon::class)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of glowingblue/redis-setup.
|
* This file is part of glowingblue/redis-setup.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2022 Glowing Blue AG.
|
* Copyright (c) 2023 Glowing Blue AG.
|
||||||
* Authors: Ian Morland, iPurpl3x, Rafael Horvat.
|
* Authors: Ian Morland, iPurpl3x, Rafael Horvat.
|
||||||
*
|
*
|
||||||
* For the full copyright and license information, please view the LICENSE.md
|
* For the full copyright and license information, please view the LICENSE.md
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
namespace GlowingBlue\RedisSetup\Extend;
|
namespace GlowingBlue\RedisSetup\Extend;
|
||||||
|
|
||||||
use Blomstra\Redis\Extend\Redis;
|
use FoF\Redis\Extend\Redis;
|
||||||
use Flarum\Extend\ExtenderInterface;
|
use Flarum\Extend\ExtenderInterface;
|
||||||
use Flarum\Extension\Extension;
|
use Flarum\Extension\Extension;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
@@ -29,9 +29,11 @@ class EnableRedis implements ExtenderInterface
|
|||||||
{
|
{
|
||||||
$config = $this->buildConfig();
|
$config = $this->buildConfig();
|
||||||
|
|
||||||
(new Redis($config))
|
/** @var Redis $redis */
|
||||||
->disable($this->getDisabledServices())
|
$redis = (new Redis($config))
|
||||||
->extend($container, $extension);
|
->disable($this->getDisabledServices());
|
||||||
|
|
||||||
|
$redis->extend($container, $extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDisabledServices(): array
|
private function getDisabledServices(): array
|
||||||
@@ -58,28 +60,23 @@ class EnableRedis implements ExtenderInterface
|
|||||||
|
|
||||||
private function buildConfig($config = []): array
|
private function buildConfig($config = []): array
|
||||||
{
|
{
|
||||||
$cache = [
|
$base = [
|
||||||
'host' => $this->getHost(),
|
'host' => $this->getHost(),
|
||||||
'password' => $this->getPassword(),
|
'password' => $this->getPassword(),
|
||||||
'port' => $this->getPort(),
|
'port' => $this->getPort(),
|
||||||
'database' => $this->getCacheDatabase(),
|
|
||||||
'prefix' => $this->getPrefix(),
|
'prefix' => $this->getPrefix(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$queue = [
|
$cache = $base + [
|
||||||
'host' => $this->getHost(),
|
'database' => static::getCacheDatabase(),
|
||||||
'password' => $this->getPassword(),
|
|
||||||
'port' => $this->getPort(),
|
|
||||||
'database' => $this->getQueueDatabase(),
|
|
||||||
'prefix' => $this->getPrefix(),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$session = [
|
$queue = $base + [
|
||||||
'host' => $this->getHost(),
|
'database' => static::getQueueDatabase(),
|
||||||
'password' => $this->getPassword(),
|
];
|
||||||
'port' => $this->getPort(),
|
|
||||||
'database' => $this->getSessionDatabase(),
|
$session = $base + [
|
||||||
'prefix' => $this->getPrefix(),
|
'database' => static::getSessionDatabase(),
|
||||||
];
|
];
|
||||||
|
|
||||||
$config = Arr::add($config, self::CACHE_KEY, $cache);
|
$config = Arr::add($config, self::CACHE_KEY, $cache);
|
||||||
@@ -89,37 +86,37 @@ class EnableRedis implements ExtenderInterface
|
|||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getHost(): string
|
public static function getHost(): string
|
||||||
{
|
{
|
||||||
return getenv('REDIS_HOST') ? getenv('REDIS_HOST') : '127.0.0.1';
|
return getenv('REDIS_HOST') ? getenv('REDIS_HOST') : '127.0.0.1';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPassword(): ?string
|
public static function getPassword(): ?string
|
||||||
{
|
{
|
||||||
return getenv('REDIS_PASSWORD') ? getenv('REDIS_PASSWORD') : null;
|
return getenv('REDIS_PASSWORD') ? getenv('REDIS_PASSWORD') : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPort(): string
|
public static function getPort(): string
|
||||||
{
|
{
|
||||||
return getenv('REDIS_PORT') ? getenv('REDIS_PORT') : '6379';
|
return getenv('REDIS_PORT') ? getenv('REDIS_PORT') : '6379';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCacheDatabase(): int
|
public static function getCacheDatabase(): int
|
||||||
{
|
{
|
||||||
return (int) getenv('REDIS_DATABASE_CACHE') ? getenv('REDIS_DATABASE_CACHE') : 1;
|
return (int) getenv('REDIS_DATABASE_CACHE') ? getenv('REDIS_DATABASE_CACHE') : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getQueueDatabase(): int
|
public static function getQueueDatabase(): int
|
||||||
{
|
{
|
||||||
return (int) getenv('REDIS_DATABASE_QUEUE') ? getenv('REDIS_DATABASE_QUEUE') : 2;
|
return (int) getenv('REDIS_DATABASE_QUEUE') ? getenv('REDIS_DATABASE_QUEUE') : 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getSessionDatabase(): int
|
public static function getSessionDatabase(): int
|
||||||
{
|
{
|
||||||
return (int) getenv('REDIS_DATABASE_SESSION') ? getenv('REDIS_DATABASE_SESSION') : 3;
|
return (int) getenv('REDIS_DATABASE_SESSION') ? getenv('REDIS_DATABASE_SESSION') : 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPrefix(): string
|
public static function getPrefix(): string
|
||||||
{
|
{
|
||||||
return getenv('REDIS_PREFIX') ? getenv('REDIS_PREFIX') : 'flarum_';
|
return getenv('REDIS_PREFIX') ? getenv('REDIS_PREFIX') : 'flarum_';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class QueueProvider extends AbstractServiceProvider
|
|||||||
/** @var QueueContract $queue */
|
/** @var QueueContract $queue */
|
||||||
$queue = resolve(QueueContract::class);
|
$queue = resolve(QueueContract::class);
|
||||||
|
|
||||||
$queues = $cache->get('blomstra.queue.queues-seen') ?? [];
|
$queues = $cache->get('fof.queue.queues-seen') ?? [];
|
||||||
|
|
||||||
if ($queue instanceof RedisQueue) {
|
if ($queue instanceof RedisQueue) {
|
||||||
$load = [];
|
$load = [];
|
||||||
@@ -67,8 +67,8 @@ class QueueProvider extends AbstractServiceProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$document->payload['blomstraQueuesSeen'] = $queues;
|
$document->payload['fofQueuesSeen'] = $queues;
|
||||||
$document->payload['blomstraQueuesLoad'] = $load ?? null;
|
$document->payload['fofQueuesLoad'] = $load ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function trackQueues(Looping $event)
|
public function trackQueues(Looping $event)
|
||||||
@@ -76,8 +76,8 @@ class QueueProvider extends AbstractServiceProvider
|
|||||||
/** @var Store $cache */
|
/** @var Store $cache */
|
||||||
$cache = resolve('cache.store');
|
$cache = resolve('cache.store');
|
||||||
|
|
||||||
$queues = $cache->get('blomstra.queue.queues-seen') ?? [];
|
$queues = $cache->get('fof.queue.queues-seen') ?? [];
|
||||||
$queues = array_merge($queues, (array) explode(',', $event->queue));
|
$queues = array_merge($queues, (array) explode(',', $event->queue));
|
||||||
$cache->put('blomstra.queue.queues-seen', array_unique($queues), 60);
|
$cache->put('fof.queue.queues-seen', array_unique($queues), 60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user