Skip to content

Add rcmds_received to user methods - #646

Merged
hxdimpf merged 1 commit into
opencaching:masterfrom
jrmajor:user-recommendations
Oct 28, 2026
Merged

hxdimpf merged 1 commit into
opencaching:masterfrom
jrmajor:user-recommendations

Conversation

@jrmajor

@jrmajor jrmajor commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Adds a rcmds_received field to services/users/users.

It returns the number of recommendations received for the caches the user currently owns. It only counts caches that OKAPI returns (Available, Temporarily unavailable and Archived), so it is equal to the sum of recommendations of the user's caches in services/caches/geocaches. Both OCPL and OCDE store recommendations in cache_rating, so the query is the same for both.

  • OCPL: the profile page shows "Number of obtained recommendations" to logged-in users. It counts caches with any status, but skips events. OKAPI can return a lower number if the user has caches that are not published or blocked (I didn't find any such recommendations in the local database). OCPL doesn't allow recommending events, but there are some old ones, so OKAPI can also return a slightly higher number.
  • OCDE: the profile page doesn't show this number. The "Recommendations" line there shows recommendations given. The total is only shown to the owner (and admins) on the "Log history" page (ownerlogs.php), and it counts caches with any status. OKAPI can return a lower number if the user has unpublished or locked caches.

The number can already be counted from the recommendations shown on each cache page, on both sites and in OKAPI. This field just adds them up.

Adopted caches count for the new owner, the same as on both sites.

Testing

Tested on local OCPL and OCDE instances with users, user, by_internal_ids and by_usernames. On OCPL, compared the numbers with the sum of recommendations of the user's caches. On OCDE, added recommendations for caches with different statuses (including unpublished and archived) and checked which were counted.

@kojoty

kojoty commented Oct 12, 2026

Copy link
Copy Markdown
Member

Please fix the conflicts.

@jrmajor
jrmajor force-pushed the user-recommendations branch from a18fea5 to 57e6559 Compare October 12, 2026 09:01
@jrmajor

jrmajor commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, rebased.

@hxdimpf hxdimpf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. The field is useful, the query matches the rest of the method (one query for all requested users, 0 for users without recommendations), and the docs are clear.

Tested on the VM (this commit on the current master), OCDE and OCPL on MariaDB 10.11 and 10.0, with the suite from #653, read-only and --write: 0 failures. users/by_username with rcmds_received works.

One observation, not a blocker: the description says the number "is equal to the sum of recommendations" of the user's caches. That holds only while the stored counters match the rows. caches/geocaches reads recommendations from the counter (stat_caches.toprating on OCDE, caches.topratings on OCPL), while this field counts the cache_rating rows.

  • On the OCPL 2018 devel dump, 16 of 56,154 published caches have a counter that differs from their rows (133,948 by counter vs 133,960 by rows).
  • On our OCDE dev database, cache_rating is empty but the counters were kept, so a user gets rcmds_received 0 while recommendations sums to 1.
  • Counting the rows is arguably the more correct number. The docs in users/user don't promise equality, so nothing needs to change. If you want the two to always agree, summing the same counter would do it.

Nit: the other queries in this method quote and escape the user IDs (array_map('\okapi\core\Db::escape_string', …)); this one implodes them as they are. They come from the database as integers, so it's safe; it's only a matter of consistency.

@jrmajor
jrmajor force-pushed the user-recommendations branch from 57e6559 to 097002e Compare October 28, 2026 12:39
@hxdimpf
hxdimpf merged commit d6f95bb into opencaching:master Oct 28, 2026
hxdimpf added a commit to OpencachingDeutschland/okapi that referenced this pull request Oct 28, 2026
Sync with opencaching/okapi: safe random functions (opencaching#652), rcmds_received (opencaching#646)
@jrmajor
jrmajor deleted the user-recommendations branch October 28, 2026 13:25
hxdimpf added a commit that referenced this pull request Nov 2, 2026
Entries in `etc/changes.xml` for the changes merged since the last
changelog PR (#665) that matter to client developers or site admins:
#649, #654, #646, #651, #682, #680, #666, #676, #672, #671, #667.

Version numbers and times were filled in by `etc/update_changes.php`.
#652 has no visible change for clients, so it has no entry.
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.

3 participants