From ded3bb59f997d73fd6c6b08dcfa0ec648995cee4 Mon Sep 17 00:00:00 2001 From: ety001 Date: Thu, 4 Jun 2026 04:51:47 +0800 Subject: [PATCH] Remove deprecated temporary analytics API and table. Metrics now live in the report service database; Scalyr shows no faucet /api/analytics traffic in the past two years. --- .env.example | 1 - .../20260603120000-drop-analytics.cjs | 32 +++++++++ db/models/analytics.js | 11 --- db/models/index.js | 12 ++-- helpers/database.js | 33 ++------- routes/api.js | 3 - routes/apiHandlers.js | 71 ------------------- src/utils/api.js | 6 -- 8 files changed, 44 insertions(+), 125 deletions(-) create mode 100644 db/migrations/20260603120000-drop-analytics.cjs delete mode 100644 db/models/analytics.js diff --git a/.env.example b/.env.example index 203cd5d7..c8bb6f2f 100644 --- a/.env.example +++ b/.env.example @@ -28,7 +28,6 @@ PORT=3001 STEEMJS_URL=https://api.steemit.com DEFAULT_REDIRECT_URI=https://steemit.com/login.html#account={{username}} REACT_DISABLE_ACCOUNT_CREATION=false -ANALYTICS_UPDATE_SUPERKEY=123456 INTERNAL_API_TOKEN=xxxx PENDING_CLAIMED_ACCOUNTS_THRESHOLD=100 COUNTRY_CODE=cn diff --git a/db/migrations/20260603120000-drop-analytics.cjs b/db/migrations/20260603120000-drop-analytics.cjs new file mode 100644 index 00000000..1e733bc8 --- /dev/null +++ b/db/migrations/20260603120000-drop-analytics.cjs @@ -0,0 +1,32 @@ +'use strict'; + +module.exports = { + up: async (queryInterface) => { + await queryInterface.dropTable('analytics'); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.createTable('analytics', { + id: { + type: Sequelize.INTEGER, + allowNull: false, + autoIncrement: true, + primaryKey: true, + }, + event_id: { + allowNull: false, + type: Sequelize.INTEGER, + }, + total: { + type: Sequelize.INTEGER, + allowNull: false, + }, + created_at: { + allowNull: false, + type: Sequelize.DATE, + }, + }); + await queryInterface.addIndex('analytics', { fields: ['event_id'] }); + await queryInterface.addIndex('analytics', { fields: ['created_at'] }); + }, +}; diff --git a/db/models/analytics.js b/db/models/analytics.js deleted file mode 100644 index 3d901720..00000000 --- a/db/models/analytics.js +++ /dev/null @@ -1,11 +0,0 @@ -export default (sequelize, DataTypes) => ( - sequelize.define('analytics', { - event_id: DataTypes.INTEGER, - total: DataTypes.INTEGER, - created_at: DataTypes.DATE, - }, { - freezeTableName: true, - underscored: true, - timestamps: false, - }) -); \ No newline at end of file diff --git a/db/models/index.js b/db/models/index.js index 4b6b0700..fa4fd1ed 100644 --- a/db/models/index.js +++ b/db/models/index.js @@ -1,27 +1,27 @@ import Sequelize, { DataTypes } from 'sequelize'; -import { readFileSync } from "fs"; +import { readFileSync } from 'fs'; import { getLogChild } from '../../helpers/logger.js'; import common, { getEnv } from '../../helpers/common.js'; import actions from './actions.js'; -import analytics from './analytics.js'; import config from './config.js'; import emailcode from './emailcode.js'; import phonecode from './phonecode.js'; import users from './users.js'; const __dirname = common.getDirnameByUrl(import.meta.url); -const allConfig = JSON.parse(readFileSync(`${__dirname}/../config/config.json`)); +const allConfig = JSON.parse( + readFileSync(`${__dirname}/../config/config.json`) +); const env = getEnv('DATABASE_NAME') || 'development'; const logger = getLogChild({ module: 'db' }); const dbConfig = allConfig[env]; -dbConfig.logging = function(msg) { +dbConfig.logging = function (msg) { logger.debug(msg); }; const sequelize = new Sequelize(getEnv(dbConfig.use_env_variable), dbConfig); const modelsHelpers = { actions, - analytics, config, emailcode, phonecode, @@ -29,7 +29,7 @@ const modelsHelpers = { }; const db = {}; -Object.keys(modelsHelpers).forEach(function(modelName) { +Object.keys(modelsHelpers).forEach(function (modelName) { db[modelName] = modelsHelpers[modelName](sequelize, DataTypes); if (db[modelName].associate) { db[modelName].associate(db); diff --git a/helpers/database.js b/helpers/database.js index d6500881..e6307d78 100644 --- a/helpers/database.js +++ b/helpers/database.js @@ -81,25 +81,6 @@ export const updateUsers = async (data, where) => db.users.update(data, where); export const query = async (q, options) => db.sequelize.query(q, options); -export const findAnalyticsLog = async (where) => db.analytics.findAll(where); -export const createAnalyticsLog = async (where, data) => - db.analytics.findOrCreate({ where, defaults: data }); - -export const updateAnalytics = async (where, data, increase = false) => { - const result = await createAnalyticsLog(where, data); - if (result[1] === false) { - // find exist data - if (increase === true) { - result[0].total += 1; - await result[0].save(); - } else { - result[0].total = data.total; - await result[0].save(); - } - } - return true; -}; - export const createEmailRecord = async (data) => db.emailcode.create(data); export const findEmailRecord = async (where) => db.emailcode.findOne(where); export const createPhoneRecord = async (data) => db.phonecode.create(data); @@ -234,7 +215,11 @@ export function clearConfigCache(key) { * Returns default ['gmail.com'] if config not found or parse fails */ export async function getWhiteEmailDomain() { - const domains = await getConfigValue('white_email_domain', ['gmail.com'], 300); + const domains = await getConfigValue( + 'white_email_domain', + ['gmail.com'], + 300 + ); return Array.isArray(domains) ? domains : ['gmail.com']; } @@ -243,11 +228,7 @@ export async function getWhiteEmailDomain() { * Returns default [] if config not found or parse fails */ export async function getPrivateWhiteEmailDomain() { - const domains = await getConfigValue( - 'private_white_email_domain', - [], - 300 - ); + const domains = await getConfigValue('private_white_email_domain', [], 300); return Array.isArray(domains) ? domains : []; } @@ -264,8 +245,6 @@ export default { phoneIsInUse, updateUsers, query, - findAnalyticsLog, - updateAnalytics, createEmailRecord, findEmailRecord, actionLimitNew, diff --git a/routes/api.js b/routes/api.js index f128243b..f4970f0a 100644 --- a/routes/api.js +++ b/routes/api.js @@ -55,7 +55,4 @@ router.post('/create_user', apiMiddleware(apiHandlers.finalizeSignup)); router.post('/create_account', apiMiddleware(apiHandlers.handleCreateAccount)); -// This api is a temporary api. This will be removed in the future! -router.get('/analytics', apiMiddleware(apiHandlers.handleAnalytics)); - export default router; diff --git a/routes/apiHandlers.js b/routes/apiHandlers.js index a97d3300..ab900540 100644 --- a/routes/apiHandlers.js +++ b/routes/apiHandlers.js @@ -64,76 +64,6 @@ async function handleGuessCountry(req) { return { location: services.locationFromIp(req.ip) }; } -/** - * Collect the analytics data - */ -async function handleAnalytics(req) { - const { event_id, superkey, total, t } = req.query; - /** - * Temporary API. - */ - if (event_id < 1) { - throw new ApiError({ - type: 'error_event_id', - status: 200, - }); - } - - // action limit - await database.logAction({ - action: 'analytics', - ip: req.ip, - }); - await database.actionLimit(req.ip); - - if (superkey) { - // In super mode we can update `total` and `created_at` fields. - const SUPERKEY_ENV = getEnv('ANALYTICS_UPDATE_SUPERKEY'); - if (!SUPERKEY_ENV) { - throw new ApiError({ - type: 'error_analytics_update_superkey_not_set', - status: 200, - }); - } - if (superkey !== SUPERKEY_ENV) { - throw new ApiError({ - type: 'error_superkey', - status: 200, - }); - } - const where = { - event_id, - created_at: `${t}T00:00:00Z`, - }; - const data = { - total, - }; - try { - await database.updateAnalytics(where, data); - } catch (error) { - req.log.error(error, 'Unable to store analytics data'); - return { success: true }; - } - } /* else { - // In normal mode we only update `total` by adding 1. - const today = new Date().toISOString().replace(/T.+/, ''); - const where = { - event_id, - created_at: `${today}T00:00:00Z`, - }; - const data = { - total: 1, - }; - try { - await database.updateAnalytics(where, data, true); - } catch (error) { - req.log.error(error, 'Unable to store analytics data'); - return { success: true }; - } - } */ - return { success: true }; -} - async function handleRequestEmailCode(req) { const ip = req.ip; const email = req.body?.email; @@ -1268,7 +1198,6 @@ export default { handleCreateAccount, handleCheckUsername, handleGuessCountry, - handleAnalytics, handleRequestEmailCode, handleConfirmEmailCode, finalizeSignup, diff --git a/src/utils/api.js b/src/utils/api.js index eb172beb..9680fae1 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -78,9 +78,3 @@ export const getPendingClaimedAccounts = (callback) => { } }); }; - -export const updateAnalytics = (eventId) => { - fetch(`/api/analytics?event_id=${eventId}`) - .then(() => {}) - .catch(() => {}); -};