refactor: remove loading sessions logic from sidebar

This commit is contained in:
Haileyesus
2026-04-25 19:56:50 +03:00
parent bb86236520
commit 3188ef5fee
10 changed files with 18 additions and 207 deletions

View File

@@ -19,7 +19,6 @@ import { getConnectableHost } from '../shared/networkHosts.js';
import { findAppRoot, getModuleDir } from './utils/runtime-paths.js';
import {
getSessionsById,
renameProjectById,
deleteSessionById,
deleteProjectById,
@@ -76,7 +75,7 @@ import pluginsRoutes from './routes/plugins.js';
import messagesRoutes from './routes/messages.js';
import providerRoutes from './modules/providers/provider.routes.js';
import { startEnabledPluginServers, stopAllPlugins, getPluginPort } from './utils/plugin-process-manager.js';
import { initializeDatabase, sessionsDb, applyCustomSessionNames } from './modules/database/index.js';
import { initializeDatabase, sessionsDb } from './modules/database/index.js';
import { configureWebPush } from './services/vapid-keys.js';
import { validateApiKey, authenticateToken, authenticateWebSocket } from './middleware/auth.js';
import { IS_PLATFORM } from './constants/config.js';
@@ -303,18 +302,6 @@ app.post('/api/system/update', authenticateToken, async (req, res) => {
}
});
// Sessions for a project; `projectId` is resolved to a path via the DB.
app.get('/api/projects/:projectId/sessions', authenticateToken, async (req, res) => {
try {
const { limit = 5, offset = 0 } = req.query;
const result = await getSessionsById(req.params.projectId, parseInt(limit), parseInt(offset));
applyCustomSessionNames(result.sessions, 'claude');
res.json(result);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// Rename project endpoint; stores the custom name on the DB row for `projectId`.
app.put('/api/projects/:projectId/rename', authenticateToken, async (req, res) => {
try {

View File

@@ -666,26 +666,6 @@ async function getSessionMessages(projectName, sessionId, limit = null, offset =
}
}
/**
* ID-based wrapper around `getSessions`.
*
* Resolves a `projectId` to the underlying Claude JSONL folder name (via the
* DB-backed project path) and defers to the legacy filesystem reader. Keeps
* the previous pagination shape so the sidebar's "Load more sessions" UI keeps
* working after the migration.
*/
async function getSessionsById(projectId, limit = 5, offset = 0) {
const projectPath = await getProjectPathById(projectId);
if (!projectPath) {
return { sessions: [], hasMore: false, total: 0 };
}
// Claude stores history under ~/.claude/projects/<encoded-path>/; derive the
// folder name from the absolute path the DB gave us.
const claudeFolderName = claudeFolderNameFromPath(projectPath);
return getSessions(claudeFolderName, limit, offset);
}
// Rename a project's display name
async function renameProject(projectName, newDisplayName) {
const config = await loadProjectConfig();
@@ -2053,7 +2033,6 @@ async function getGeminiCliSessionMessages(sessionId) {
// based helpers (`getSessions`, `renameProject`, `deleteSession`, etc.) are
// kept as internal implementation details of the id-based wrappers below.
export {
getSessionsById,
getSessionMessages,
renameProjectById,
deleteSessionById,