mirror of
https://github.com/civitai/civitai.git
synced 2026-09-20 22:08:18 +08:00
adding notification rows
This commit is contained in:
+1
-1
@@ -60,7 +60,7 @@ services:
|
||||
restart: unless-stopped
|
||||
|
||||
meilisearch:
|
||||
image: getmeili/meilisearch:v1.2
|
||||
image: getmeili/meilisearch:v1.11
|
||||
container_name: meilisearch
|
||||
ports:
|
||||
- 7700:7700
|
||||
|
||||
+81
-1
@@ -24,9 +24,11 @@ import {
|
||||
import { capitalize, pull, range, without } from 'lodash-es';
|
||||
import format from 'pg-format';
|
||||
import { constants } from '~/server/common/constants';
|
||||
import { CheckpointType, ModelType } from '~/server/common/enums';
|
||||
import { CheckpointType, ModelType, NotificationCategory } from '~/server/common/enums';
|
||||
import { IMAGE_MIME_TYPE, VIDEO_MIME_TYPE } from '~/server/common/mime-types';
|
||||
import { notifDbWrite } from '~/server/db/notifDb';
|
||||
import { pgDbWrite } from '~/server/db/pgDb';
|
||||
import { notificationProcessors } from '~/server/notifications/utils.notifications';
|
||||
// import { fetchBlob } from '~/utils/file-utils';
|
||||
|
||||
const numRows = 1000;
|
||||
@@ -76,6 +78,29 @@ const insertRows = async (table: string, data: any[][]) => {
|
||||
}
|
||||
};
|
||||
|
||||
const insertNotifRows = async (table: string, data: any[][]) => {
|
||||
console.log(`Inserting ${data.length} rows into ${table}`);
|
||||
|
||||
// language=text
|
||||
const query = 'INSERT INTO %I VALUES %L ON CONFLICT DO NOTHING RETURNING ID';
|
||||
|
||||
try {
|
||||
const ret = await notifDbWrite.query<{ id: number }>(format(query, table, data));
|
||||
|
||||
if (ret.rowCount === data.length) console.log(`\t-> ✔️ Inserted ${ret.rowCount} rows`);
|
||||
else if (ret.rowCount === 0) console.log(`\t-> ⚠️ Inserted 0 rows`);
|
||||
else console.log(`\t-> ⚠️ Only inserted ${ret.rowCount} of ${data.length} rows`);
|
||||
|
||||
return ret.rows.map((r) => r.id);
|
||||
} catch (error) {
|
||||
const e = error as MixedObject;
|
||||
console.log(`\t-> ❌ ${e.message}`);
|
||||
console.log(`\t-> Detail: ${e.detail}`);
|
||||
if (e.where) console.log(`\t-> where: ${e.where}`);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const truncateRows = async () => {
|
||||
console.log('Truncating tables');
|
||||
await pgDbWrite.query(
|
||||
@@ -2769,6 +2794,59 @@ const genRows = async (truncate = true) => {
|
||||
*/
|
||||
};
|
||||
|
||||
/**
|
||||
* Notification
|
||||
*/
|
||||
const genNotifications = (num: number) => {
|
||||
const ret = [];
|
||||
|
||||
const types = Object.keys(notificationProcessors);
|
||||
|
||||
for (let step = 1; step <= num; step++) {
|
||||
const row = [
|
||||
step, // id
|
||||
rand(types), // type
|
||||
faker.string.uuid(), // key // TODO this isn't right, but it works
|
||||
rand(Object.values(NotificationCategory)), // category
|
||||
'{}', // details // TODO
|
||||
];
|
||||
|
||||
ret.push(row);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
/**
|
||||
* UserNotification
|
||||
*/
|
||||
const genUserNotifications = (num: number, notifIds: number[], userIds: number[]) => {
|
||||
const ret = [];
|
||||
|
||||
for (let step = 1; step <= num; step++) {
|
||||
const row = [
|
||||
step, // id
|
||||
rand(notifIds), // notificationId
|
||||
rand(userIds), // userId
|
||||
fbool(), // viewed
|
||||
faker.date.past({ years: 3 }).toISOString(), // createdAt
|
||||
];
|
||||
|
||||
ret.push(row);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
const genNotificationRows = async () => {
|
||||
const userData = await pgDbWrite.query<{ id: number }>(`SELECT id from "User"`);
|
||||
const userIds = userData.rows.map((u) => u.id);
|
||||
|
||||
const notifs = genNotifications(numRows);
|
||||
const notifIds = await insertNotifRows('Notification', notifs);
|
||||
|
||||
const userNotifs = genUserNotifications(numRows, notifIds, userIds);
|
||||
await insertNotifRows('UserNotification', userNotifs);
|
||||
};
|
||||
|
||||
const main = async () => {
|
||||
await pgDbWrite.query('REASSIGN OWNED BY doadmin, civitai, "civitai-jobs" TO postgres');
|
||||
await pgDbWrite.query(
|
||||
@@ -2777,6 +2855,8 @@ const main = async () => {
|
||||
await pgDbWrite.query('GRANT ALL ON ALL TABLES IN schema public TO "postgres"');
|
||||
await genRows();
|
||||
await pgDbWrite.query('REFRESH MATERIALIZED VIEW "CoveredCheckpointDetails"');
|
||||
|
||||
await genNotificationRows();
|
||||
};
|
||||
|
||||
main().then(() => {
|
||||
|
||||
@@ -2,8 +2,14 @@ import { articleNotifications } from '~/server/notifications/article.notificatio
|
||||
import { BareNotification } from '~/server/notifications/base.notifications';
|
||||
import { bountyNotifications } from '~/server/notifications/bounty.notifications';
|
||||
import { buzzNotifications } from '~/server/notifications/buzz.notifications';
|
||||
import { clubNotifications } from '~/server/notifications/club.notifications';
|
||||
import { collectionNotifications } from '~/server/notifications/collection.notifications';
|
||||
import { commentNotifications } from '~/server/notifications/comment.notifications';
|
||||
import { cosmeticShopNotifications } from '~/server/notifications/cosmetic-shop.notifications';
|
||||
import { creatorsProgramNotifications } from '~/server/notifications/creators-program.notifications';
|
||||
import { featuredNotifications } from '~/server/notifications/featured.notifications';
|
||||
import { followNotifications } from '~/server/notifications/follow.notifications';
|
||||
import { imageNotifications } from '~/server/notifications/image.notifications';
|
||||
import { mentionNotifications } from '~/server/notifications/mention.notifications';
|
||||
import { modelNotifications } from '~/server/notifications/model.notifications';
|
||||
import { reactionNotifications } from '~/server/notifications/reaction.notifications';
|
||||
@@ -12,14 +18,8 @@ import { reviewNotifications } from '~/server/notifications/review.notifications
|
||||
import { systemNotifications } from '~/server/notifications/system.notifications';
|
||||
import { unpublishNotifications } from '~/server/notifications/unpublish.notifications';
|
||||
import { userJourneyNotifications } from '~/server/notifications/user-journey.notifications';
|
||||
import { collectionNotifications } from '~/server/notifications/collection.notifications';
|
||||
import { imageNotifications } from '~/server/notifications/image.notifications';
|
||||
import { clubNotifications } from '~/server/notifications/club.notifications';
|
||||
import { creatorsProgramNotifications } from '~/server/notifications/creators-program.notifications';
|
||||
import { followNotifications } from '~/server/notifications/follow.notifications';
|
||||
import { cosmeticShopNotifications } from '~/server/notifications/cosmetic-shop.notifications';
|
||||
|
||||
const notificationProcessors = {
|
||||
export const notificationProcessors = {
|
||||
...mentionNotifications,
|
||||
...modelNotifications,
|
||||
...reviewNotifications,
|
||||
|
||||
Reference in New Issue
Block a user