@cryptotaxi247 / netdata-1 / commits / 31c9be1c0

a simple journal optimization (#16099)

Costa Tsaousis committed Oct 3, 2023 at 12:09 UTC 31c9be1c073ff869b74c7551f3494669503e63e7
1 file changed +24 -26
libnetdata/facets/facets.c
+24 -26
@@ -1738,10 +1738,12 @@ bool facets_row_finished(FACETS *facets, usec_t usec) {
1738
1739 if((facets->query && facets->keys_filtered_by_query && !facets->current_row.keys_matched_by_query) ||
1740 (facets->timeframe.before_ut && usec > facets->timeframe.before_ut) ||
1741 - (facets->timeframe.after_ut && usec < facets->timeframe.after_ut)) {
1741 + (facets->timeframe.after_ut && usec < facets->timeframe.after_ut) ||
1742 + !facets_is_entry_within_anchor(facets, usec) /* this has to be last */) {
1743 // this row is not useful
1744 // 1. not matched by full text search, or
1744 - // 2. not in our timeframe
1745 + // 2. not in our timeframe, or
1746 + // 3. is not selected by the anchor
1747 facets_reset_keys_with_value_and_row(facets);
1748 return false;
1749 }
@@ -1770,42 +1772,38 @@ bool facets_row_finished(FACETS *facets, usec_t usec) {
1772 facets->histogram.key = k;
1773 }
1774
1773 - bool within_anchor = facets_is_entry_within_anchor(facets, usec);
1775 + if(selected_keys >= total_keys - 1) {
1776 + size_t found = 0;
1777 + (void) found;
1778
1775 - if(likely(within_anchor)) {
1776 - if(selected_keys >= total_keys - 1) {
1777 - size_t found = 0;
1778 - (void) found;
1779 + for(size_t p = 0; p < entries; p++) {
1780 + FACET_KEY *k = facets->keys_with_values.array[p];
1781
1780 - for(size_t p = 0; p < entries; p++) {
1781 - FACET_KEY *k = facets->keys_with_values.array[p];
1782 + size_t counted_by = selected_keys;
1783
1783 - size_t counted_by = selected_keys;
1784 + if(counted_by != total_keys && !k->key_values_selected_in_row)
1785 + counted_by++;
1786
1785 - if(counted_by != total_keys && !k->key_values_selected_in_row)
1786 - counted_by++;
1787 + if(counted_by == total_keys) {
1788 + FACET_VALUE *v = FACET_VALUE_GET_CURRENT_VALUE(k);
1789 + v->final_facet_value_counter++;
1790
1788 - if(counted_by == total_keys) {
1789 - FACET_VALUE *v = FACET_VALUE_GET_CURRENT_VALUE(k);
1790 - v->final_facet_value_counter++;
1791 -
1792 - found++;
1793 - }
1791 + found++;
1792 }
1795 -
1796 - internal_fatal(!found, "We should find at least one facet to count this row");
1793 }
1794
1799 - if(selected_keys == total_keys) {
1800 - // we need to keep this row
1801 - facets_histogram_update_value(facets, usec);
1802 - facets_row_keep(facets, usec);
1803 - }
1795 + internal_fatal(!found, "We should find at least one facet to count this row");
1796 + }
1797 +
1798 + if(selected_keys == total_keys) {
1799 + // we need to keep this row
1800 + facets_histogram_update_value(facets, usec);
1801 + facets_row_keep(facets, usec);
1802 }
1803
1804 facets_reset_keys_with_value_and_row(facets);
1805
1808 - return selected_keys == total_keys && within_anchor;
1806 + return selected_keys == total_keys;
1807 }
1808
1809 // ----------------------------------------------------------------------------