Skip to content

Commit f7ad779

Browse files
author
Leszek Wiesner
authored
Orion 5.0.0 (#365)
* - Curator schema and Curator view permissions - Support for setting channel YppStatus with a tier - `isYtSyncEnabled` field + related mutations - Removal of redundant `excludeChannel` / `excludeVideo` mutations (`excludeContent` should be used instead) * - Relevance service - Updated channelWeight / videoRelevance formula - Separated index creation from migrations - Moved views creation script to `/src` * - Reduce the usage of NextEntityId to mappings only - Remove NextEntityId from offchainState migration * Formatting * Fix linter errors * Restore accidently removed `save` in `createAccount`, fix notifications test * Fix notifications tests (part 2) * Bump version to 5.0.0 and adjust migrations * Fix notifications tests (part 3) * Fix notifications tests (part 4) * Final improvements * Initial CHANGELOG * Fix: SumTo constraint * Fix: TypeOrm subscribers config * Fix rate query, adjust percentiles * Fix: Prevent index creation from breaking import
1 parent 90e6406 commit f7ad779

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2767
-2345
lines changed

.env

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# LOCAL DEV ENVIRONMENT
2-
32
ORION_ENV=development
43
DEV_DISABLE_SAME_SITE=true
54

@@ -17,6 +16,9 @@ PROCESSOR_PROMETHEUS_PORT=3337
1716
GQL_PORT=4350
1817
# Auth api port
1918
AUTH_API_PORT=4074
19+
# RabbitMQ
20+
RABBITMQ_PORT=5672
21+
RABBITMQ_URL=amqp://orion_rabbitmq
2022

2123
# Archive gateway url
2224
ARCHIVE_GATEWAY_URL=${CUSTOM_ARCHIVE_GATEWAY_URL:-http://localhost:8888/graphql}
@@ -33,17 +35,10 @@ KILL_SWITCH_ON=false
3335
VIDEO_VIEW_PER_USER_TIME_LIMIT=10
3436
# Operator API secret
3537
OPERATOR_SECRET=this-is-not-so-secret-change-it
36-
# every 50 views video relevance score will be recalculated
37-
VIDEO_RELEVANCE_VIEWS_TICK=50
38-
# [
39-
# newness (negative number of days since created) weight,
40-
# views weight,
41-
# comments weight,
42-
# rections weights,
43-
# [joystream creation weight, YT creation weight],
44-
# Default channel weight/bias
45-
# ]
46-
RELEVANCE_WEIGHTS="[1, 0.03, 0.3, 0.5, [7,3], 1]"
38+
# every 10 views video relevance score will be recalculated
39+
VIDEO_RELEVANCE_VIEWS_TICK=10
40+
# every time a channel is followed / unfollowed, its weight will be recalculated
41+
CHANNEL_WEIGHT_FOLLOWS_TICK=1
4742
COMMENT_TIP_TIERS='{"SILVER": 100, "GOLD": 500, "DIAMOND": 1000}'
4843
MAX_CACHED_ENTITIES=5000
4944
APP_PRIVATE_KEY=this-is-not-so-secret-change-it

CHANGELOG.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,168 @@
1+
# 5.0.0
2+
3+
## Changes
4+
5+
### Channel weights and video relevance calculation
6+
7+
- **Automatic channel weights:** The new _Relevance Service_ supports automatic calculation of channel weights based on factors such as channel's _cumulative revenue_, _YPP tier_, _number of followers_, _CRT liquidity_ and _CRT volume_ (the weight of which can be configured).
8+
- **Improved video relevance formula:** Factors such as number of _views_ / _comments_ / _reactions_ are now represented as `0 - 1` range rates, which simplifies assigning adequate weights.
9+
- **Fixed video relevance calculation bugs** (such as https://github.com/Joystream/orion/issues/361)
10+
- **More flexible configuration** (updates interval or number of scored videos per channel can now be configured via the GraphQL API)
11+
12+
### Improved permissions system
13+
14+
- **New view/read permission levels: `VIEW_CURATOR_SCHEMA`, `VIEW_ADMIN_SCHEMA`** . Thanks to the introduction of a new `curator` database schema, the view permissions to access hidden content (hidden / censored channels and videos) can be separated from view permissions to access more sensitive data (Orion account emails, session data, configuration etc.) and other root-level permissions.
15+
- Changing YPP status of a channel now requires `SET_CHANNEL_YPP_STATUS` permission.
16+
- Changing other app-scoped configuration settings which don't have a separate permission category now requires `SET_APP_CONFIGS` permission.
17+
- Changing the new relevance service weights and configuration requires `SET_RELEVANCE_WEIGHTS` and `SET_RELEVANCE_CONFIG` permissions respectively.
18+
19+
### Support for setting channel YPP tiers and sync status
20+
21+
- `Channel.yppStatus` now includes YPP tier
22+
- `Channel` now has a new `isYtSyncEnabled` field
23+
- Those values can be set via the new `setChannelYppStatus` and `setChannelYoutubeSyncEnabled` mutations respectively (given sufficient permissions)
24+
25+
### Fixed _Offchain state_ migrations
26+
27+
- Fixed https://github.com/Joystream/orion/issues/360
28+
29+
### Performance impovements (indexes, faster sync etc.)
30+
31+
- **New indexes:** New PostgreSQL indexes have been added to support faster filtering / ordering of channels and videos in Atlas and [Content admin dashboard](https://github.com/Joystream/gleev/issues/72).
32+
- **Post-sync index creation:** The creation of some custom PostgreSQL indexes has been delayed to post-sync phase (ie. the time when processor catches up to chain head) to allow faster from-scratch syncing of new Orion instances and faster migrations.
33+
34+
35+
## Upgrade instructions
36+
37+
TBD.
38+
39+
## Affected components:
40+
- **(M)** `assets/patches/@subsquid+typeorm-config+2.0.2.patch` (support for custom TypeORM subscribers)
41+
- Processor
42+
- **(M)** `processor.ts`
43+
- support for new `RelevanceService`
44+
- support for post-sync index generation (via `model/indexes.ts`)
45+
- improved logging
46+
- **(A)** `mappings/subscribers/TransactionCommitSubscriber.ts`
47+
- **(M)** `mappings/utils.ts` (added `relevanceQueuePublisher` instance)
48+
- Event handlers:
49+
- **(M)** `Content.ChannelCreated`
50+
- **(M)** `Content.VideoCreated`
51+
- Events triggering re-calculation of channel / video relevance:
52+
- **(M)** `Content.ChannelRewardUpdated`
53+
- **(M)** `Content.ChannelRewardClaimedAndWithdrawn`
54+
- **(M)** `Content.EnglishAuctionSettled`
55+
- **(M)** `Content.BidMadeCompletingAuction`
56+
- **(M)** `Content.OpenAuctionBidAccepted`
57+
- **(M)** `Content.OfferAccepted`
58+
- **(M)** `Content.NftBought`
59+
- **(M)** `Members.MemberRemarked`
60+
- `ReactVideo` (meta-action)
61+
- `CreateComment` (meta-action)
62+
- `DeleteComment` (meta-action)
63+
- `MakeChannelPayment` (meta-action)
64+
- Migrations:
65+
- **(!) Re-generated all data migrations**
66+
- **(!) Custom indexes are no longer part of migrations, moved to `model/indexes.ts`**
67+
- **(M)** `db/migrations/1000000000000-Admin.js`
68+
- **(D)** `db/migrations/2200000000000-Indexes.js`
69+
- **(R)** `db/viewDefinitions.js` => `model/views.ts`
70+
- **(M)** `db/generateViewsMigration.js`
71+
- Schema / Models:
72+
- Entities moved from `admin` to `curator` schema
73+
- **(M)** `OwnedNft`
74+
- **(M)** `Auction`
75+
- **(M)** `Bid`
76+
- **(M)** `Channel`
77+
- **(M)** `BannedMember`
78+
- **(M)** `Event`
79+
- **(M)** `NftHistoryEntry`
80+
- **(M)** `NftActivity`
81+
- **(M)** `UserInteractionCount`
82+
- **(M)** `VideoViewEvent`
83+
- **(M)** `Report`
84+
- **(M)** `NftFeaturingRequest`
85+
- **(M)** `ChannelFollow`
86+
- **(M)** `StorageDataObject`
87+
- **(M)** `MarketplaceToken`
88+
- **(M)** `CommentReaction`
89+
- **(M)** `Comment`
90+
- **(M)** `VideoCategory`
91+
- **(M)** `Video`
92+
- **(M)** `VideoFeaturedInCategory`
93+
- **(M)** `VideoHero`
94+
- **(M)** `VideoMediaMetadata`
95+
- **(M)** `VideoMediaEncoding`
96+
- **(M)** `License`
97+
- **(M)** `VideoSubtitle`
98+
- **(M)** `VideoReaction`
99+
- Entities with removed `@index` decorators (index defs moved to `model/indexes.ts`):
100+
- **(M)** `Channel` (`createdAt`, `language`)
101+
- **(M)** `Video` (`createdAt`, `orionLanguage`, `videoRelevance`)
102+
- Auth server:
103+
- **(M)** `auth-server/handlers/createAccount.ts` (dependency on `NextEntityId` removed)
104+
- Entities removed:
105+
- **(D)** `ChannelVerification`
106+
- **(D)** `ChannelSuspension`
107+
- **(D)** `Exclusion`
108+
- **(M)** `OperatorPermission`
109+
- **(M)** `Channel`
110+
- added `isYtSyncEnabled`
111+
- extended `yppStatus`
112+
- **(M)** `ChannelYppStatus`
113+
- **(A)** `model/views.ts` (PostgreSQL view creation utils)
114+
- **(A)** `model/indexes.ts` (PostgreSQL index creation utils)
115+
- Auth server:
116+
- **(M)** `openapi.yml` spec
117+
- **(M)** `anonymousAuth` route
118+
- GraphQL server:
119+
- **(M)** `server-extension/check.ts` (more granular view permissions, `curator` / `admin` schema)
120+
- **(M)** `server-extension/utils.ts`
121+
- **(A)** `server-extension/subscribers/TransactionCommitSubscriber.ts`
122+
- Fixed permissions:
123+
- **(M)** `setAppAssetStorage`
124+
- **(M)** `setAppNameAlt`
125+
- setNewNotificationAssetRoot
126+
- setMaxAttemptsOnMailDelivery
127+
- **(A)** `setChannelYppStatus`
128+
- **(M)** `followChannel`
129+
- **(M)** `addVideoView`
130+
- **(D)** `suspendChannels` (replaced by `setChannelYppStatus`)
131+
- **(D)** `verifyChannel` (replaced by `setChannelYppStatus`)
132+
- **(D)** `excludeChannel` (duplicate of `excludeContent`)
133+
- **(D)** `excludeVideo` (duplicate of `excludeContent`)
134+
- **(D)** `setVideoWeights`
135+
- **(D)** `setNewNotificationCenterPath` (duplicate of `setMaxAttemptsOnMailDelivery`)
136+
- **(D)** `setChannelsWeights`
137+
- **(M)** `processCommentsCensorshipStatusUpdate`
138+
- **(A)** `setRelevanceWeights` mutation
139+
- **(A)** `setRelevanceServiceConfig` mutation
140+
- **(A) NEW RELEVANCE SERVICE (`relevance-service`)**
141+
- **(D)** `utils/VideoRelevanceManager.ts`
142+
- Config:
143+
- **Defaults now can be specified directly in `src/utils/config.ts`** (but can still be overriden by `env` variables and/or db config)
144+
- **(A)** `RELEVANCE_SERVICE_CONFIG`
145+
- **(A)** `CHANNEL_WEIGHT_FOLLOWS_TICK`
146+
- Environment:
147+
- **(A)** `RABBITMQ_PORT` (required)
148+
- **(A)** `RABBITMQ_URL` (required)
149+
- **(A)** `CHANNEL_WEIGHT_FOLLOWS_TICK` (required)
150+
- **(M)** `VIDEO_RELEVANCE_VIEWS_TICK` (`50` => `10`)
151+
- **(D)** `RELEVANCE_WEIGHTS`
152+
- Utils:
153+
- **(M)** `utils/OrionVideoLanguageManager.ts` (`admin` => `curator` schema)
154+
- **(M)** `utils/customMigrations/setOrionLanguageProvider.ts` (`admin` => `curator` schema)
155+
- **(D)** `utils/nextEntityId.ts`
156+
- **(M)** `notification/helpers.ts` (dependency on `NextEntityId` removed)
157+
- **(M)** `utils/offchainState.ts`
158+
- **(M)** `utils/overlay.ts` (prevent deadlocks)
159+
- **(M)** `docker-compose.yml`
160+
- Added RabbitMQ queue
161+
- Added relevance service
162+
- **(M)** `Makefile`
163+
- Turned off `SQD_DEBUG` for mappings in `process`
164+
- Added `relevance-service`
165+
1166
# 4.5.0
2167
## Affected components:
3168
- Auth server:

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
process: migrate
2-
@SQD_DEBUG=sqd:processor:mapping node -r dotenv-expand/config lib/processor.js
2+
@node -r dotenv-expand/config lib/processor.js
33

44
install:
55
@rm -rf node_modules # clean up node_modules to avoid issues with patch-package
@@ -18,6 +18,9 @@ serve:
1818
serve-auth-api:
1919
@npm run auth-server-start
2020

21+
relevance-service:
22+
@npm run relevance-service-start
23+
2124
migrate:
2225
@npx squid-typeorm-migration apply
2326

assets/patches/@subsquid+typeorm-config+2.0.2.patch

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
diff --git a/node_modules/@subsquid/typeorm-config/lib/config.js b/node_modules/@subsquid/typeorm-config/lib/config.js
2-
index 046611f..28fd4e2 100644
2+
index 046611f..04a0ad2 100644
33
--- a/node_modules/@subsquid/typeorm-config/lib/config.js
44
+++ b/node_modules/@subsquid/typeorm-config/lib/config.js
5-
@@ -28,22 +28,22 @@ const path = __importStar(require("path"));
5+
@@ -28,22 +28,26 @@ const path = __importStar(require("path"));
66
const process = __importStar(require("process"));
77
const connectionOptions_1 = require("./connectionOptions");
88
const namingStrategy_1 = require("./namingStrategy");
@@ -13,6 +13,9 @@ index 046611f..28fd4e2 100644
1313
- let model = resolveModel(path.join(dir, 'lib/model'));
1414
+ let model = resolveModel(path.join(dir, "lib/model"));
1515
let migrationsDir = path.join(dir, exports.MIGRATIONS_DIR);
16+
+ let subscribers = process.env.TYPEORM_SUBSCRIBERS_DIR
17+
+ ? [`${path.join(dir, process.env.TYPEORM_SUBSCRIBERS_DIR)}/*.js`]
18+
+ : undefined
1619
return {
1720
- type: 'postgres',
1821
+ type: "postgres",
@@ -21,6 +24,7 @@ index 046611f..28fd4e2 100644
2124
- migrations: [migrationsDir + '/*.js'],
2225
- ...(0, connectionOptions_1.createConnectionOptions)()
2326
+ migrations: [migrationsDir + `/${options?.file || "*.js"}`],
27+
+ subscribers,
2428
+ ...(0, connectionOptions_1.createConnectionOptions)(),
2529
};
2630
}

db/generateViewsMigration.js

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const generateViewsMigration = (versionNumber) => {
88
const className = `Views${versionNumber}`
99
const fileName = `${versionNumber}-Views.js`
1010
const fileContent = `
11-
const { getViewDefinitions } = require('../viewDefinitions')
11+
const { createViews } = require('../../lib/model/views')
1212
1313
module.exports = class ${className} {
1414
name = '${className}'
@@ -21,31 +21,11 @@ module.exports = class ${className} {
2121
id SERIAL PRIMARY KEY,
2222
height INT
2323
);\`)
24-
const viewDefinitions = getViewDefinitions(db);
25-
for (const [tableName, viewConditions] of Object.entries(viewDefinitions)) {
26-
if (Array.isArray(viewConditions)) {
27-
await db.query(\`
28-
DROP VIEW IF EXISTS "\${tableName}" CASCADE
29-
\`)
30-
await db.query(\`
31-
CREATE OR REPLACE VIEW "\${tableName}" AS
32-
SELECT *
33-
FROM "admin"."\${tableName}" AS "this"
34-
WHERE \${viewConditions.map(cond => \`(\${cond})\`).join(' AND ')}
35-
\`);
36-
} else {
37-
await db.query(\`
38-
CREATE OR REPLACE VIEW "\${tableName}" AS (\${viewConditions})
39-
\`);
40-
}
41-
}
42-
}
24+
await createViews(db);
25+
}
4326
4427
async down(db) {
45-
const viewDefinitions = this.getViewDefinitions(db)
46-
for (const viewName of Object.keys(viewDefinitions)) {
47-
await db.query(\`DROP VIEW "\${viewName}"\`)
48-
}
28+
await dropViews(db);
4929
}
5030
}
5131
`

db/migrations/1000000000000-Admin.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ module.exports = class Admin1000000000000 {
22
name = 'Admin1000000000000'
33

44
async up(db) {
5-
// Create a new "admin" schema through which the "hidden" entities can be accessed
5+
// Create "admin" and "curator" schemas, through which some of the "hidden" entities can be accessed
66
await db.query(`CREATE SCHEMA "admin"`)
7-
// Create admin user with "admin" schema in default "search_path"
7+
await db.query(`CREATE SCHEMA "curator"`)
8+
// Create admin user with "admin" and "curator" schemas in default "search_path"
89
await db.query(
910
`CREATE USER "${process.env.DB_ADMIN_USER}" WITH PASSWORD '${process.env.DB_ADMIN_PASS}'`
1011
)
1112
await db.query(`GRANT pg_read_all_data TO "${process.env.DB_ADMIN_USER}"`)
1213
await db.query(`GRANT pg_write_all_data TO "${process.env.DB_ADMIN_USER}"`)
13-
await db.query(`ALTER USER "${process.env.DB_ADMIN_USER}" SET search_path TO admin,public`)
14+
await db.query(
15+
`ALTER USER "${process.env.DB_ADMIN_USER}" SET search_path TO admin,curator,public`
16+
)
1417
}
1518

1619
async down(db) {

0 commit comments

Comments
 (0)