From 794ff1e255811985ad84c83af18148c5ed10fca7 Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Sat, 13 Dec 2025 09:45:13 -0800 Subject: [PATCH] Remove tag cache refresh logic from AppInformationService (#2166) * Remove tag cache refresh logic from AppInformationService Eliminated the _refresh_tags method and its scheduled interval from AppInformationService. This change removes the tag cache refresh functionality, likely due to refactoring or deprecation of tag-based app discovery. * Remove AI usage testing contributor docs --- .../src/modules/apps/AppInformationService.js | 77 ++----------------- src/backend/src/services/ai/docs/README.md | 6 -- .../ai/docs/contributors/ai_usage_testing.md | 44 ----------- 3 files changed, 8 insertions(+), 119 deletions(-) delete mode 100644 src/backend/src/services/ai/docs/contributors/ai_usage_testing.md diff --git a/src/backend/src/modules/apps/AppInformationService.js b/src/backend/src/modules/apps/AppInformationService.js index d9767d6a8..8484d6a55 100644 --- a/src/backend/src/modules/apps/AppInformationService.js +++ b/src/backend/src/modules/apps/AppInformationService.js @@ -66,10 +66,8 @@ class AppInformationService extends BaseService { ['__on_boot.consolidation'] () { (async () => { - // await new Promise(rslv => setTimeout(rslv, 500)) - if ( ENABLE_REFRESH_APP_CACHE ) { - await this._refresh_app_cache(); + this._refresh_app_cache(); /** * Refreshes the application cache by querying the database for all apps and updating the key-value store. * @@ -84,7 +82,6 @@ class AppInformationService extends BaseService { }, 30 * 1000); } - await this._refresh_app_stats(); /** * Refreshes the cache of recently opened apps. * This method updates the 'recent' collection with the UIDs of apps sorted by their most recent timestamp. @@ -92,24 +89,25 @@ class AppInformationService extends BaseService { * @async * @returns {Promise} A promise that resolves when the cache has been refreshed. */ + this._refresh_app_stats(); asyncSafeSetInterval(async () => { this._refresh_app_stats(); - }, 120 * 1000); + }, 240 * 1000); - // This stat is more expensive so we don't update it as often - await this._refresh_app_stat_referrals(); /** * Refreshes the app referral statistics. * This method is computationally expensive and thus runs less frequently. * It queries the database for user counts referred by each app's origin URL. * + * This stat is more expensive so we don't update it as often + * * @async */ + this._refresh_app_stat_referrals(); asyncSafeSetInterval(async () => { this._refresh_app_stat_referrals(); }, 15 * MINUTE); - await this._refresh_recent_cache(); /** * Refreshes the recent cache by updating the list of recently added or updated apps. * This method fetches all app data, filters for approved apps, sorts them by timestamp, @@ -118,23 +116,10 @@ class AppInformationService extends BaseService { * @async * @private */ + this._refresh_recent_cache(); asyncSafeSetInterval(async () => { this._refresh_recent_cache(); - }, 120 * 1000); - - await this._refresh_tags(); - /** - * Refreshes the tags cache by iterating through all approved apps, - * extracting their tags, and organizing them into a structured format. - * This method updates the `this.tags` object with the latest tag information. - * - * @async - * @method - * @memberof AppInformationService - */ - asyncSafeSetInterval(async () => { - this._refresh_tags(); - }, 120 * 1000); + }, 240 * 1000); })(); } @@ -697,52 +682,6 @@ class AppInformationService extends BaseService { this.collections.recent = apps.map(app => app.uid).slice(0, 50); } - /** - * Refreshes the cache of tags associated with apps. - * - * This method iterates through all approved apps, extracts their tags, - * and organizes them into a structured format for quick lookups. - * - * This data is used by the `/query/app` router to facilitate tag-based - * app discovery and categorization. - * - * @async - * @returns {Promise} - */ - async _refresh_tags () { - const app_keys = kv.keys('apps:uid:*'); - - let apps = []; - for ( const key of app_keys ) { - const app = kv.get(key); - apps.push(app); - } - - apps = apps.filter(app => app.approved_for_listing); - apps.sort((a, b) => { - return b.timestamp - a.timestamp; - }); - - const new_tags = {}; - - for ( const app of apps ) { - const app_tags = (app.tags ?? '').split(',') - .map(tag => tag.trim()) - .filter(tag => tag.length > 0); - - for ( const tag of app_tags ) { - if ( ! new_tags[tag] ) new_tags[tag] = {}; - new_tags[tag][app.uid] = true; - } - } - - for ( const tag in new_tags ) { - new_tags[tag] = Object.keys(new_tags[tag]); - } - - this.tags = new_tags; - } - /** * Deletes an application from the system. * diff --git a/src/backend/src/services/ai/docs/README.md b/src/backend/src/services/ai/docs/README.md index c18f2f20d..0ddcb1728 100644 --- a/src/backend/src/services/ai/docs/README.md +++ b/src/backend/src/services/ai/docs/README.md @@ -13,12 +13,6 @@ This directory contains documentation for the PuterAI module, which provides AI - [API Request Examples](./api_examples.md) - Examples of API requests to PuterAI services -### For Contributors - -Documentation for contributors can be found in the [contributors](./contributors/) directory: - -- [AI Usage Testing](./contributors/ai_usage_testing.md) - Guide for testing and reporting AI usage - ## Related Documentation For more information about the overall Puter documentation structure, see the [documentation meta guide](../../../../../doc/docmeta.md). \ No newline at end of file diff --git a/src/backend/src/services/ai/docs/contributors/ai_usage_testing.md b/src/backend/src/services/ai/docs/contributors/ai_usage_testing.md deleted file mode 100644 index 4abb02619..000000000 --- a/src/backend/src/services/ai/docs/contributors/ai_usage_testing.md +++ /dev/null @@ -1,44 +0,0 @@ -# AI Usage Testing and Reporting - -This document provides guidance for testing and reporting AI usage in the Puter platform. - -## Manual Testing for AI Usage Reporting - -When testing AI usage reporting and tracking, it's sometimes necessary to manipulate the timestamps of usage records for testing purposes. This can be useful for validating reporting over specific time periods or for troubleshooting issues with usage limits. - -### Backdating AI Usage Records - -To move all records in the `ai_usage` table back by one week, you can use the following SQL query for SQLite: - -```sql -UPDATE ai_usage -SET created_at = datetime(created_at, '-7 days'); -``` - -This query updates the `created_at` timestamp for all records in the table, shifting them back by 7 days. - -### Common Testing Scenarios - -1. **Testing daily usage limits**: Backdate some records to earlier in the current day to test daily usage limit calculations. - -2. **Testing monthly reports**: Distribute usage records across a month to validate monthly usage reports. - -3. **Testing billing cycles**: Adjust record timestamps to span multiple billing cycles to ensure proper attribution. - -## Usage Table Structure - -The `ai_usage` table tracks all AI service usage with the following key fields: - -- `user_id`: The user who made the request -- `service_name`: The AI service that was used (e.g., 'openai', 'claude') -- `model_name`: The specific model that was used -- `cost`: Expected cost in microcents (ยตยข) -- `value_uint_1`: Input tokens -- `value_uint_2`: Output tokens -- `created_at`: When the usage occurred - -For the complete table definition, see the [ai_usage table schema](../../../../services/database/sqlite_setup/0033_ai-usage.sql). - -## Resetting Test Data - -After testing, you may want to reset the timestamps to their original values. This is only possible if you've kept a backup of the original data or timestamps. \ No newline at end of file