jesus cabrera
jesus cabrera

Reputation: 1

when i do a query with spring data jpa , findTop10XX if the value is less the query takes a long time

public interface AlarmRepository extends MongoRepository<Alarm, String> {

List<Alarm> queryFirst10ByHubAndDeletedAndDataspace(String idHub, boolean b, String dataspace, Pageable sort);

List<Alarm> queryTop10ByHubAndDeletedAndDataspace(String idHub, boolean b, String dataspace, Pageable sort);

List<Alarm> findTop10ByHubAndDeletedAndDataspace(String idHub, boolean b, String dataspace, Pageable sort);
}

index de hub in alarms

@CompoundIndex(name="alarm_hub_id_index", def = "{'hub.$id' : 1}")
@CompoundIndex(name="alarm_hub_id_dt_event_desc_index", def = "{'hub.$id' : 1, 'dtEvent' : -1}")

postmant get

/rest/titan/v1/alarms/historical?hub=62285d951a110632228d6a0e&dataspace=200&sort=dtEvent,desc

If the data number value is greater than or equal to that indicated in the top, the query time does not exceed 200ms, on the other hand, if the data is less than the value entered in the top or in the page, the query is very slow, even return a timeout

class Alarm

    @Document(collection="alarms")
@CompoundIndex(name="alarm_dt_event_dataspace_index", def = "{'dtEvent' : 1, 'dataspace' : 1}")
@CompoundIndex(name="alarm_hub_id_index", def = "{'hub.$id' : 1}")
@CompoundIndex(name="alarm_hub_id_dt_event_desc_index", def = "{'hub.$id' : 1, 'dtEvent' : -1}")
@CompoundIndex(name="alarm_hub_id_dt_event_desc_dataspace_index", def = "{'hub.$id' : 1, 'dtEvent' : -1, 'dataspace' : 1}")
public class Alarm extends CommonEntity implements Cloneable{
    //@ApiModelProperty(notes = "Date start Alarm")
    //@Field
    @Indexed(name = "dt_event_alarm_index",unique = false)
    private DateTime dtEvent;
    //@ApiModelProperty(notes = "Source of Alarm")
    @Field
    private Source source;
    @Field
    private String comments;
    @Field
    private Boolean active;
    //@ApiModelProperty(notes = "Severity of Alarm")
    @Field
    private Severity severity;
    //@ApiModelProperty(notes = "Detail of Alarm")
    @Field
    private DetailAlarm detail;
    //@ApiModelProperty(notes = "Hub of Alarm",required = false)
    @Field
    @DBRef
    private Hub hub;
    //@ApiModelProperty(notes = "Hub of Alarm",required = false)
    //@Indexed(name = "traffic_controller_alarm_index")
    @Field
    @DBRef
    private TrafficController trafficController;
    @Field
    private ElementTypeAlarm elementType;
    @Transient
    private String dtEventForKafka;
    @Transient
    private String dataspaceForKafka;
    ... geter seters 
}

Upvotes: 0

Views: 76

Answers (0)

Related Questions