merge tenders which have the same procedure id - worker performance fix
This commit is contained in:
@@ -20,6 +20,7 @@ type TenderRepository interface {
|
||||
GetByID(ctx context.Context, id string) (*Tender, error)
|
||||
GetByContractNoticeID(ctx context.Context, contractNoticeID string) (*Tender, error)
|
||||
GetByNoticePublicationID(ctx context.Context, noticePublicationID string) (*Tender, error)
|
||||
GetByContractFolderID(ctx context.Context, contractFolderID string) (*Tender, error)
|
||||
FindTendersWithContentXML(ctx context.Context, limit, skip int) ([]Tender, error)
|
||||
GetTenderCountByCountry(ctx context.Context) (map[string]int64, error)
|
||||
GetTenderCountByType(ctx context.Context) (map[string]int64, error)
|
||||
@@ -52,6 +53,7 @@ func NewRepository(mongoManager *orm.ConnectionManager, logger logger.Logger) Te
|
||||
*orm.CreateUniqueIndex("tender_id_idx", bson.D{{Key: "tender_id", Value: 1}}),
|
||||
*orm.NewIndex("project_name_idx", bson.D{{Key: "project_name", Value: 1}}),
|
||||
*orm.NewIndex("contract_notice_id_idx", bson.D{{Key: "contract_notice_id", Value: 1}}),
|
||||
*orm.NewIndex("contract_folder_id_idx", bson.D{{Key: "contract_folder_id", Value: 1}}),
|
||||
*orm.NewIndex("status_idx", bson.D{{Key: "status", Value: 1}}),
|
||||
*orm.NewIndex("source_idx", bson.D{{Key: "source", Value: 1}}),
|
||||
*orm.NewIndex("country_code_idx", bson.D{{Key: "country_code", Value: 1}}),
|
||||
@@ -158,9 +160,16 @@ func (r *tenderRepository) GetByContractNoticeID(ctx context.Context, contractNo
|
||||
return &result.Items[0], nil
|
||||
}
|
||||
|
||||
// GetByNoticePublicationID retrieves a tender by notice publication ID
|
||||
// GetByNoticePublicationID retrieves a tender by notice publication ID.
|
||||
// Matches both the canonical NoticePublicationID and any id retained in RelatedNoticePublicationIDs
|
||||
// so historical TED detail links keep resolving after a tender update from a follow-up notice.
|
||||
func (r *tenderRepository) GetByNoticePublicationID(ctx context.Context, noticePublicationID string) (*Tender, error) {
|
||||
filter := bson.M{"notice_publication_id": noticePublicationID}
|
||||
filter := bson.M{
|
||||
"$or": []bson.M{
|
||||
{"notice_publication_id": noticePublicationID},
|
||||
{"related_notice_publication_ids": noticePublicationID},
|
||||
},
|
||||
}
|
||||
pagination := orm.Pagination{Limit: 1}
|
||||
|
||||
result, err := r.ormRepo.FindAll(ctx, filter, pagination)
|
||||
@@ -179,6 +188,34 @@ func (r *tenderRepository) GetByNoticePublicationID(ctx context.Context, noticeP
|
||||
return &result.Items[0], nil
|
||||
}
|
||||
|
||||
// GetByContractFolderID retrieves a tender by its procedure-level identifier (ContractFolderID).
|
||||
// TED groups multiple notice publications (e.g. competition notice + result notice) under the same
|
||||
// ContractFolderID, so this lookup is the authoritative way to find the existing tender for a procedure
|
||||
// when a follow-up notice arrives. Returns the most recently updated match if there are several.
|
||||
func (r *tenderRepository) GetByContractFolderID(ctx context.Context, contractFolderID string) (*Tender, error) {
|
||||
filter := bson.M{"contract_folder_id": contractFolderID}
|
||||
pagination := orm.Pagination{
|
||||
Limit: 1,
|
||||
SortField: "updated_at",
|
||||
SortOrder: -1,
|
||||
}
|
||||
|
||||
result, err := r.ormRepo.FindAll(ctx, filter, pagination)
|
||||
if err != nil {
|
||||
r.logger.Error("Failed to get tender by contract folder ID", map[string]interface{}{
|
||||
"contract_folder_id": contractFolderID,
|
||||
"error": err.Error(),
|
||||
})
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(result.Items) == 0 {
|
||||
return nil, orm.ErrDocumentNotFound
|
||||
}
|
||||
|
||||
return &result.Items[0], nil
|
||||
}
|
||||
|
||||
// FindTendersWithContentXML returns tenders that still have TED XML (for backfill after notices were deleted).
|
||||
func (r *tenderRepository) FindTendersWithContentXML(ctx context.Context, limit, skip int) ([]Tender, error) {
|
||||
filter := bson.M{"content_xml": bson.M{"$exists": true, "$ne": ""}}
|
||||
|
||||
Reference in New Issue
Block a user