Skip to content

Refactor duplicated code and consolidate WigTube module#34

Draft
Copilot wants to merge 7 commits intomainfrom
copilot/refactor-duplicated-code
Draft

Refactor duplicated code and consolidate WigTube module#34
Copilot wants to merge 7 commits intomainfrom
copilot/refactor-duplicated-code

Conversation

Copy link

Copilot AI commented Jan 15, 2026

Eliminates ~216 lines of duplicated code across WigTube and game modules by extracting common functionality into 3 shared utility modules, and consolidates WigTube by removing unnecessary MySQL infrastructure and migration files.

Part 1: Code Deduplication

Database Utilities (wigtube-db-common.js)

Extracts 5 duplicated functions from wigtube-db.js and wigtube-db-mysql.js:

  • getOfflineData() / saveOfflineData() - localStorage operations
  • formatTimestamp() - relative time formatting
  • formatViewCount() - smart view count formatting (K/M/B)
  • calculateStarRating() - star rating calculation with 0-5 clamping

Handles both array and object rating formats. Adds MIN_RATING / MAX_RATING constants.

Debug Utilities (wigtube-debug.js)

Centralizes debug logging initialization duplicated across 4 browser files:

  • Factory function createDebugLogger(moduleName) for module-specific loggers
  • Single URL parameter check instead of repeated initialization

Game Utilities (game-utils.js)

Extracts background star initialization duplicated in sublimator.js and breakout.js:

  • initializeBackgroundStars(count, width, height, sizeIndex, rng, color)
  • Removes identical 10-line loops from both games

All consuming modules include comprehensive fallbacks to maintain functionality if utilities fail to load.

Part 2: WigTube Consolidation & Cleanup

Removed MySQL Infrastructure (12 files)

  • Deleted entire scripts/api/ directory (MySQL API server, upload server, Node.js dependencies, shell scripts)
  • Removed apps/browser/pages/mysql-test.html
  • Removed scripts/apps/browser/wigtube-db-mysql.js

Removed Migration Files (2 files)

  • Removed migrate-wigtube.html and scripts/migrations/migrate-wigtube-to-maps.js

Removed Initialization Files (3 files)

  • Removed database initialization module, HTML page, and static JSON data file

Cleaned Up Documentation

  • Removed 4 outdated documentation files
  • Created unified docs/WIGTUBE.md with current Firebase architecture

Unified Database Module

  • Consolidated to single wigtube-db.js using Firebase Firestore backend
  • Updated comments to reflect current architecture
  • All changes are backward compatible

Impact Summary

Deduplication: 14 files modified, 182 lines added (utilities), 216 lines removed (duplication)

Consolidation: 20 files removed, 5,286 lines deleted, architecture simplified to single unified Firebase module

Total: 21 files deleted, 3 files modified, 3 utility modules created, 1 documentation file created

Net Change: -5,320 lines of code

✅ All core WigTube functionality preserved
✅ 100% backward compatible
✅ CodeQL security scan: 0 alerts

Original prompt

Find and refactor duplicated code


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits January 15, 2026 07:26
Co-authored-by: MichaelD1B <181105440+MichaelD1B@users.noreply.github.com>
Co-authored-by: MichaelD1B <181105440+MichaelD1B@users.noreply.github.com>
Co-authored-by: MichaelD1B <181105440+MichaelD1B@users.noreply.github.com>
…ency

Co-authored-by: MichaelD1B <181105440+MichaelD1B@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for improved maintainability Refactor duplicated code into shared utility modules Jan 15, 2026
Copilot AI requested a review from 102457 January 15, 2026 07:38
Copy link
Collaborator

102457 commented Jan 20, 2026

@copilot Refractor Wigtube to more as one instead of so seperated and remove all the unnessery stuff since im using cloudflare now to send stuff over

and delete the files that arent being used anymore

and clean up the docs

Copilot AI and others added 2 commits January 20, 2026 15:03
Co-authored-by: MichaelD1B <181105440+MichaelD1B@users.noreply.github.com>
Co-authored-by: MichaelD1B <181105440+MichaelD1B@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 20, 2026

@copilot Refractor Wigtube to more as one instead of so seperated and remove all the unnessery stuff since im using cloudflare now to send stuff over

and delete the files that arent being used anymor...

Done! WigTube has been consolidated and cleaned up:

Removed 20 unnecessary files (5,286 lines deleted):

  • MySQL API server and all related infrastructure
  • Migration tools (no longer needed)
  • Initialization scripts
  • Outdated documentation

Consolidated to unified Firebase module:

  • Single wigtube-db.js with shared utilities
  • Simplified architecture diagram
  • New unified docs/WIGTUBE.md documentation

Commits:

  • 9176a72 - Removed all MySQL/migration files
  • e1c1cb5 - Clarified Firebase backend architecture

✅ CodeQL security scan: 0 alerts
✅ All core WigTube functionality preserved
✅ Backward compatible

Copilot AI changed the title Refactor duplicated code into shared utility modules Refactor duplicated code and consolidate WigTube module Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants