We have moved to Github. Please open tickets there.

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#3366 closed Documentation (fixed)

Update docs for get_entities_from_annotation_count() because it uses sum instead of count

Reported by: cash Owned by:
Priority: normal Milestone: Elgg 1.7.9
Component: Core Version: 1.7
Severity: minor Keywords:
Cc: brett@… Difficulty: easy

Description

count_annotations() uses the slower sum rather than count. I think there is carry over into the 1.8 functions on this too. I got around a 20% speed up by switching.

Change History (10)

comment:1 Changed 2 years ago by brettp

Where are you seeing this? In 1.7 count_annotations() passes 'count' as the $sum param to get_annotations_calculate_x(), which is then used as the MySQL function.

In 1.8 count_annotations() (eventually) passes 'count' as the 'annotation_calculation' option to elgg_get_metastring_based_objects().

Sum is used for get_entities_from_annotation_count(), but this is because we want the sum of all annotations and not the count of annotations on the entity. A better name might have been egef_annotation_sum(), but since the function is deprecated by egef_annotation_calculation() it doesn't make sense to change it now.

comment:2 Changed 2 years ago by cash

  • Milestone changed from Needs Review to Elgg 1.7.9

comment:3 Changed 2 years ago by cash

  • Summary changed from count_annotations() uses sum rather than count to get_entities_from_annotation_count() uses sum rather than count

comment:4 Changed 2 years ago by brettp

  • Resolution set to wontfix
  • Status changed from new to closed

Using count() instead of sum() changes what that function does. Currently it says "return all entities ordered by the *sum of value* of all annotations named 'X' on that entity." Using count would change it to "return all entities ordered by the *number* of annotations named 'X' on that entity." I don't think we want to change this. Please reopen if needed.

comment:5 Changed 2 years ago by cash

Why is it called get_entities_from_annotation_count() if it doesn't use count?

We use it for plugin downloads, correct? Why do we want to sum thousands of 1's rather than counting them?

comment:6 Changed 2 years ago by brettp

I don't know why it's called that, but it's been that way since it was introduced in 1.5. Options are:

  • Make the functionality match the name and possibly break sites excepting it to sum.
  • Introduce in 1.7 gefa_sum() to sum and gefa_count() to count. Could possibly deprecate gefa_count() to gefa_sum() by using default args and a parent function. This would mean all sites would essentially use gefa_sum() anyway.
  • Leave as is and understand it's a performance hit. It's been fixed in 1.8 anyway.

comment:7 Changed 2 years ago by cash

How about: add a warning to the documentation that this function does not do what you think it does.

Then we update the plugin repository to use get_entities_from_annotations_calculate_x() directly for a big performance boost.

comment:8 Changed 2 years ago by brettp

  • Resolution wontfix deleted
  • Status changed from closed to reopened
  • Summary changed from get_entities_from_annotation_count() uses sum rather than count to Update docs for get_entities_from_annotation_count() because it uses sum instead of count
  • Type changed from Defect to Documentation

Works for me.

comment:9 Changed 2 years ago by brettp

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [svn:9129]) Fixes #3366: Added warning to get_entities_from_annotation_count() that it doesn't actually count.

comment:10 Changed 2 years ago by brettp

(In [svn:9147]) Refs #3510, #3366. Added warning about count vs sum in egef_annotation_count() to trunk.

Note: See TracTickets for help on using tickets.