Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove corresponding log entries when a link is deleted #3684

Open
3 tasks done
RavanH opened this issue Dec 12, 2023 · 1 comment
Open
3 tasks done

Remove corresponding log entries when a link is deleted #3684

RavanH opened this issue Dec 12, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@RavanH
Copy link

RavanH commented Dec 12, 2023

Code of Conduct

Submission validity

  • This is not a personal support request, that should be posted on discussions community.
  • I checked current issues and this request isn't a duplicate of an existing issue, opened or closed.

Summary

When a link is deleted, the corresponding log entries remain in the DB.

Motivation

Trying to keep the DB as lean as possible.

Describe the solution

No response

@RavanH RavanH added the enhancement New feature or request label Dec 12, 2023
@dgw
Copy link
Member

dgw commented Dec 12, 2023

I think most users would consider this sane behavior. Links cannot be undeleted, therefore permanently removing the logs about deleted links shouldn't be a problem.

Note: There is a delete_link action hook that a plugin could use to DELETE FROM the YOURLS_DB_TABLE_LOG table itself:

function yourls_delete_link_by_keyword( $keyword ) {
// Allow plugins to short-circuit the whole function
$pre = yourls_apply_filter( 'shunt_delete_link_by_keyword', null, $keyword );
if ( null !== $pre ) {
return $pre;
}
$table = YOURLS_DB_TABLE_URL;
$keyword = yourls_sanitize_keyword($keyword);
$delete = yourls_get_db()->fetchAffected("DELETE FROM `$table` WHERE `keyword` = :keyword", array('keyword' => $keyword));
yourls_do_action( 'delete_link', $keyword, $delete );
return $delete;
}

However I think there is merit to including a function that does this in includes/functions-infos.php like the one above, that takes a keyword and deletes the relevant logs. Maybe it'd be called yourls_delete_stats_for_keyword().

While a plugin can run a raw SQL query to accomplish this, I think plugins needing to mess around in a core table isn't ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants