Fixed queue issue#84
Open
rishitha-ravi wants to merge 9 commits into
Open
Conversation
arunasd463
reviewed
Jun 23, 2026
| Session session = sessionFactory.openSession(); | ||
| List<Long> documentIds = null; | ||
| try { | ||
| String hql = "SELECT DISTINCT docSciName.documentId FROM DocSciName docSciName " |
Contributor
There was a problem hiding this comment.
can name this as sql just to maintain uniformity.
arunasd463
reviewed
Jun 23, 2026
| query.setParameter("taxonConceptIds", taxonConceptIds); | ||
| documentIds = query.list(); | ||
|
|
||
| logger.info("Found {} unique documentIds for taxonConceptIds: {}", |
Contributor
There was a problem hiding this comment.
do we need info in dao functions? we already have this in error.
arunasd463
reviewed
Jun 23, 2026
| return documentIds; | ||
| } | ||
|
|
||
| public void deleteByDocumentId(Long documentId) { |
Contributor
There was a problem hiding this comment.
same changes needed like getDocumentIdsByTaxonConceptIds.
arunasd463
reviewed
Jun 23, 2026
| query.setParameter("bulkIds", bulkIds); | ||
| results = query.list(); | ||
|
|
||
| logger.info("Found {} documents for bulkIds: {}", results != null ? results.size() : 0, bulkIds); |
arunasd463
reviewed
Jun 23, 2026
| } | ||
|
|
||
| public List<Document> findByBulkIds(List<Long> bulkIds) { | ||
| logger.info("Fetching documents by bulkIds: {}", bulkIds); |
arunasd463
reviewed
Jun 23, 2026
| } | ||
|
|
||
| public List<Long> getDocumentIdsByTaxonConceptIds(List<Long> taxonConceptIds) { | ||
| logger.info("Fetching unique documentIds by taxonConceptIds: {}", taxonConceptIds); |
arunasd463
reviewed
Jun 23, 2026
| System.out.println("------------name finder process started-----------"); | ||
| parsePdfWithGNFinder(ufile.getPath(), documentId); | ||
| } | ||
| if (externalUrl != null && externalUrl.startsWith("http")) { |
Contributor
There was a problem hiding this comment.
consult this with @thomvee.Both will execute if both becomes true.
arunasd463
reviewed
Jun 23, 2026
| try { | ||
| List<Long> documentIds = docSciNameDao.getDocumentIdsByTaxonConceptIds(updateData.getBulkIds()); | ||
| List<Document> documents = documentDao.findByBulkIds(documentIds); | ||
| for (Document doc : documents) { |
Contributor
There was a problem hiding this comment.
return early if no documents is found
arunasd463
reviewed
Jun 23, 2026
| } | ||
|
|
||
| // Rerun for deleted | ||
| if (updateData.getDeleteRecoIds() != null) { |
Contributor
There was a problem hiding this comment.
this logic can be improved using set because it performs same action. please refer
public void handleTaxonByName(TaxonomyUpdateData updateData) {
if (updateData == null) return;
// 1. Accumulate all unique Taxon IDs that need processing across all scenarios
Set<Long> taxonIdsToProcess = new HashSet<>();
if (updateData.getBulkIds() != null) {
taxonIdsToProcess.addAll(updateData.getBulkIds());
}
if (updateData.getDeleteRecoIds() != null) {
taxonIdsToProcess.addAll(updateData.getDeleteRecoIds());
}
if (!Objects.equals(updateData.getOldName(), updateData.getName()) && updateData.getTargetId() != null) {
taxonIdsToProcess.add(updateData.getTargetId());
}
// 2. Early exit if there is absolutely nothing to process
if (taxonIdsToProcess.isEmpty()) {
return;
}
// 3. Delegate to a single, optimized processing pipeline
processDocumentsForTaxonIds(taxonIdsToProcess);
}
private void processDocumentsForTaxonIds(Set<Long> taxonIds) {
try {
// Fetch all associated document IDs in one single database call
List<Long> documentIds = docSciNameDao.getDocumentIdsByTaxonConceptIds(new ArrayList<>(taxonIds));
if (documentIds == null || documentIds.isEmpty()) {
logger.info("No documents found for the requested taxon updates.");
return;
}
// Fetch all Document objects in bulk
List<Document> documents = documentDao.findByBulkIds(documentIds);
// Local Cache Map to avoid hitting the resource API repeatedly for duplicate uFileIds
Map<String, UFile> uFileCache = new HashMap<>();
for (Document doc : documents) {
try {
UFile resource = null;
if (doc.getuFileId() != null) {
String uFileIdStr = doc.getuFileId().toString();
// Look up in the local cache first before making an API call
if (uFileCache.containsKey(uFileIdStr)) {
resource = uFileCache.get(uFileIdStr);
} else {
logger.debug("Fetching resource from service for uFileId: {}", uFileIdStr);
resource = resourceService.getUFilePath(uFileIdStr);
if (resource != null && resource.getPath() != null) {
resource.setPath(resource.getPath().replace("/documents", ""));
}
// Save to local cache (even if null, to avoid repeating a failing/empty request)
uFileCache.put(uFileIdStr, resource);
}
}
// Process the scientific names extraction safely
updateScientificNames(doc.getId(), resource, doc.getExternalUrl());
} catch (com.strandls.resource.ApiException e) {
logger.error("API error fetching resource for documentId: {} (uFileId: {}). Skipping.",
doc.getId(), doc.getuFileId(), e);
} catch (Exception e) {
logger.error("Unexpected error processing documentId: {}. Skipping.", doc.getId(), e);
}
}
} catch (Exception e) {
logger.error("Critical error while batch processing taxonomy documents", e);
}
}
arunasd463
requested changes
Jun 23, 2026
arunasd463
left a comment
Contributor
There was a problem hiding this comment.
Please check my comments and update the code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.