Критические оптимизации для снижения потребления памяти
- Кэширование только текущей недели:
* Кэш хранит только текущие недели (без параметра wk)
* Запросы с конкретной неделей (wk указан) не кэшируются
* Ключ кэша изменен с `${group}_${wk}` на `group`
* Уменьшен maxCacheSize с 100 до 50 записей
- Условный парсинг навигации по неделям:
* Парсинг навигации выполняется только если weekNavigationEnabled === true
* Если навигация выключена, parseWeekNavigation не вызывается
* Экономит память и CPU при выключенной навигации
* Параметр shouldParseWeekNavigation передается через getSchedule -> parsePage
- Результат:
* Значительное снижение потребления памяти
* Кэш содержит только актуальные данные (текущие недели)
* Парсинг навигации выполняется только при необходимости
Измененные файлы:
- src/pages/[group].tsx - логика кэширования только текущей недели
- src/app/agregator/schedule.ts - параметр для условного парсинга
- src/app/parser/schedule.ts - условный вызов parseWeekNavigation
5.1 KiB
Schedule for колледж связи пгути
Reskin of https://lk.ks.psuti.ru/ since it lacks mobile support.
Tech stack & features
- React 19.2.0 with Next.js 16.0.3 (pages router)
- Tailwind CSS
- @shadcn/ui components (built with Radix UI)
- JSDOM for parsing scraped pages, rehydration strategy for cache
- TypeScript 5.6.0 with types for each package
- Telegram Bot API (via [node-telegram-bot-api]) for parsing failure notifications
- Custom js parser for teachers' photos
- Accessability & tab navigation support
- Dark theme with automatic switching based on system settings
Tools used: pnpm, eslint, react-icons. Deployed with Netlify and supported by Cloudflare.
Known issues
- Previous week cannot be accessed if you enter from main "/" Workaround: Locate to next week, then enter previous twice.
Development
Prerequisites
- Node.js 20+ (see
.nvmrc) - npm 10+ or pnpm
Local development
# Install dependencies
npm install
# or
pnpm install
# Run development server
npm run dev
# or
pnpm dev
Docker deployment
Build and run with Docker
# Build the image
docker build -t kspguti-schedule .
# Run the container
docker run -p 3000:3000 kspguti-schedule
Using Docker Compose
# Build and start
docker-compose up -d
# View logs
docker-compose logs -f
# Stop
docker-compose down
Environment variables: Edit docker-compose.yml to add your environment variables:
PROXY_URL- URL for schedule parsingPARSING_FAILURE_NOTIFICATIONS_TELEGRAM_BOTAPI_TOKEN- Telegram bot tokenPARSING_FAILURE_NOTIFICATIONS_TELEGRAM_CHAT_ID- Telegram chat ID
Production deployment
Netlify
The project includes netlify.toml for automatic deployment configuration.
Docker
The Dockerfile uses Next.js standalone output for optimized production builds. The image includes:
- Multi-stage build for smaller image size
- Non-root user for security
- Health checks
- Production optimizations
System installation (Linux systemd)
Install the application directly on a Linux system as a systemd service:
Prerequisites:
- Linux system with systemd
- Node.js 20+ installed
- Root/sudo access
- ICU library (for Node.js):
- Arch Linux:
sudo pacman -S icu - Ubuntu/Debian:
sudo apt-get install libicu-dev - Fedora/RHEL/CentOS:
sudo dnf install libicuorsudo yum install libicu
- Arch Linux:
Installation:
# Clone the repository
git clone <repository-url>
cd kspguti-schedule
# Copy example and edit .env
cp .env.production.example .env
nano .env
# Run the installation script
sudo ./scripts/install.sh
The installation script will:
- Check Node.js and npm versions
- Copy files to
/opt/kspguti-schedule - Install dependencies
- Build the production version
- Install and enable systemd service
Configuration:
- Edit environment variables:
sudo nano /opt/kspguti-schedule/.env
The installation script will:
- Copy
.envfile from source directory if it exists - Preserve existing
.envin installation directory if it already exists - Create
.envfrom.env.production.exampleif no.envfile is found
- Update systemd service if needed:
sudo nano /etc/systemd/system/kspguti-schedule.service
Managing the service:
Use the management script for easy service control:
# Start the service
sudo ./scripts/manage.sh start
# Stop the service
sudo ./scripts/manage.sh stop
# Restart the service
sudo ./scripts/manage.sh restart
# Check status
./scripts/manage.sh status
# View logs
./scripts/manage.sh logs
./scripts/manage.sh logs -f # Follow logs
# Update application
sudo ./scripts/manage.sh update
# Enable/disable autostart
sudo ./scripts/manage.sh enable
sudo ./scripts/manage.sh disable
Or use systemctl directly:
sudo systemctl start kspguti-schedule
sudo systemctl stop kspguti-schedule
sudo systemctl restart kspguti-schedule
sudo systemctl status kspguti-schedule
sudo journalctl -u kspguti-schedule -f
Service configuration:
- Installation directory:
/opt/kspguti-schedule - Service user:
www-data - Port:
3000(configurable via environment variables) - Logs:
journalctl -u kspguti-schedule
Environment variables:
See .env.production.example or .example.env for available options. The application uses .env file in production:
PROXY_URL- URL for schedule parsing (optional)PARSING_FAILURE_NOTIFICATIONS_TELEGRAM_BOTAPI_TOKEN- Telegram bot token (optional)PARSING_FAILURE_NOTIFICATIONS_TELEGRAM_CHAT_ID- Telegram chat ID (optional)
Other platforms
The project can be deployed to any platform supporting Node.js 20+:
- Vercel
- Railway
- DigitalOcean App Platform
- AWS App Runner
- Any Docker-compatible platform