Skip to content

Refactor: collection summary api#199

Open
Rossi-Luciano wants to merge 6 commits intoscieloorg:masterfrom
Rossi-Luciano:refactor/collection-summary-api
Open

Refactor: collection summary api#199
Rossi-Luciano wants to merge 6 commits intoscieloorg:masterfrom
Rossi-Luciano:refactor/collection-summary-api

Conversation

@Rossi-Luciano
Copy link
Copy Markdown

O que esse PR faz?

Refatora o uso do dicionário local choices.collections substituindo-o por chamadas à função get_collection_summary, que consulta diretamente a API do ArticleMeta para obter o nome e a URL da coleção.

Onde a revisão poderia começar?

A revisão pode começar pelos trechos onde choices.collections.get(...) era utilizado - normalmente em métodos que retornam o nome ou a URL da coleção com base em self.collection_acronym.
Os pontos alterados fazem uso agora da função get_collection_summary, definida no módulo utilitário xylose/choices.py.

Como este poderia ser testado manualmente?

  1. Execute a aplicação normalmente.
  2. Acesse funcionalidades que envolvem dados da coleção (ex: exibição de nome e URL).
  3. Verifique que:
    • Para acrônimos válidos (como "ven"), o nome e o domínio aparecem corretamente.
    • Para acrônimos inexistentes, o nome aparece como "Undefined: " e a URL como None.

Algum cenário de contexto que queira dar?

NA.

Screenshots

NA.

Quais são tickets relevantes?

TK #198

Referências

NA.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors collection metadata retrieval from a static dictionary to dynamic API calls. The hardcoded collections dictionary (containing collection names and domains) is removed and replaced with functions that fetch collection metadata from the ArticleMeta API at runtime.

Key changes:

  • Removed static collections dictionary from choices.py
  • Added three new functions to dynamically fetch collection data via API: fetch_collection_metadata(), get_collection_name_and_url(), and get_collection_summary()
  • Updated scielo_domain and collection_name properties across Issue, Journal, and Article classes to use the new API-based approach

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
xylose/choices.py Removed static collections dictionary and added API-based collection metadata fetching with retry logic
xylose/scielodocument.py Updated collection name and domain retrieval methods to use new API-based functions instead of static dictionary lookups

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

[u'Undefined: %s' % self.collection_acronym, None]
)[1] or None
summary = choices.get_collection_summary(self.collection_acronym)
return summary[0] if len(summary) > 0 and summary[0] else f'Undefined: {self.collection_acronym}'
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scielo_domain method should return summary[1] (the URL) instead of summary[0] (the name). According to the method's docstring and similar implementations at lines 256 and 1074, it should retrieve the collection domain, not the name.

Suggested change
return summary[0] if len(summary) > 0 and summary[0] else f'Undefined: {self.collection_acronym}'
return summary[1] if len(summary) > 1 and summary[1] else f'Undefined: {self.collection_acronym}'

Copilot uses AI. Check for mistakes.
)[0]
if self.collection_acronym:
summary = choices.get_collection_summary(self.collection_acronym)
return summary[0] if len(summary) > 0 and summary[0] else f'Undefined: {self.collection_acronym}'
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing return statement when self.collection_acronym is None or falsy. The original code always returned a value, but this implementation returns None implicitly when the condition fails. Add an explicit return None or handle the else case.

Suggested change
return summary[0] if len(summary) > 0 and summary[0] else f'Undefined: {self.collection_acronym}'
return summary[0] if len(summary) > 0 and summary[0] else f'Undefined: {self.collection_acronym}'
return None

Copilot uses AI. Check for mistakes.
session.mount(base_url, adapter)

try:
response = session.get(full_url, timeout=10)
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function creates a new session with retry configuration on every call. Consider implementing a module-level session or caching mechanism to avoid the overhead of creating a new session for each collection lookup, especially if multiple collections are queried in succession.

Copilot uses AI. Check for mistakes.
Comment on lines +263 to +264
metadata = fetch_collection_metadata(collection_code)
return get_collection_name_and_url(metadata) if metadata else []
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding caching for collection metadata to avoid repeated API calls for the same collection code. The static dictionary was effectively a cache; removing it without replacement could significantly impact performance if the same collection is queried multiple times.

Copilot uses AI. Check for mistakes.
Comment on lines +227 to +228
except (requests.RequestException, ValueError):
return None
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error handling silently suppresses all exceptions without logging. Consider logging failures to help diagnose API connectivity issues or data parsing problems in production environments.

Copilot uses AI. Check for mistakes.
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