Files
Vaessl/backend/src/main/java/com/vaessl/app/sync/SyncController.java
T
kasun 65ff109800 add session-gated /sync endpoint and prune stale vectors after reindex
SyncController/SyncService/SyncProvider mirror the existing search
dispatch pattern: a session-gated controller routes a SyncRequest to
the provider registered for its ServiceType. HomeboxSyncProvider pages
through the full Homebox catalog, embedding each page via
EmbeddingService, and now collects every item ID it sees across all
pages before pruning anything no longer present upstream in one
deleteStaleVectorEntries call at the end - deleting per page would
treat items on other pages as stale and wipe them out.
2026-07-04 01:08:42 +02:00

41 lines
1.3 KiB
Java

package com.vaessl.app.sync;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.vaessl.app.shared.SessionKeys;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
@RestController
public class SyncController {
private final SyncService syncService;
public SyncController(SyncService syncService) {
this.syncService = syncService;
}
/**
* Triggers a vector-store sync for the requested service. Returns {@code 401 Unauthorized}
* if there is no active session.
*/
@PostMapping("/sync")
public ResponseEntity<Object> syncVectorStore(@Valid @RequestBody SyncRequest request,
HttpServletRequest httpReq) {
HttpSession session = httpReq.getSession(false);
if (session == null
|| session.getAttribute(SessionKeys.connectionId(request.serviceType())) == null) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
syncService.syncServiceVectorStore(request);
return ResponseEntity.noContent().build();
}
}