Environment/Context

I use this module with a YOURLS installation via a custom service and have this service set to json return data encoding (trivial, the others work just the same) with the tag shorturl, respectively. The url is like so:

https://eg.com/yourls-api.php?signature=000xyz111&format=json&action=shorturl&url=

When using either the "Shorten URLS's" block or the form at https://drupal.example.com/shorten, an appropriate short url is returned, and all data is successfully stored in the YOURLS database.

However, when I enable the "Short URL" block which fetches and displays an appropriate short url for the current page, I get some unexpected behavior.

The Problem

1. There are multiple concurrent requests (4 or 5) that get registered at my YOURLS installation, the YOURLS community seems to be aware of this effect and have written some code to address it. While this seems to work, managing the effect and not the cause seems problematic.

2. 3 or 4 out of 5 (or so) of these links are not stored with an appropriate title, instead the url appears as the title tag. This is YOURLS's fall back behavior when no appropriate title is returned. This also happens with the single link returned when using the concurrency-fix plugin referred to above, and when merely adding a new node unless that node has an alias. This appears true weather "prefer alias" is set to true or false.

Manually re-adding any link that is associated with any of this behavior via either YOURLS's admin or public interfaces, or via some other API client, renders appropriately handled links, and all data is successfully retrieved and stored in the YOURLS database. It only happens with that block.

The Fix

In the meantime, I have written a plugin for YOURLS that will conditionally perform a title refetch when the original fetch fails. This plugin relies on an additional API argument to trigger the watchdog. This will necessitate the new (format independent) API call:

https://eg.com/yourls-api.php?refetch=true&signature=000xyz111&format=json&action=shorturl&url=

Json encoding is included as an example only, it is not required. The plugin has a few more features, but in terms of this issue, the refetch=true argument will do the trick, for now.

I'm attaching the plugin to this post for easy access, however it is better to get it from github, here, where you will find the most up to date code.

Hopefully this will come in handy for anybody else using YOURLS with this plugin. Why would this behavior (specifically #2) be happening?

CommentFileSizeAuthor
#2 YOURLS-title-refetch-1.0.0.tar_.gz15.1 KBalienseer23
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alienseer23 created an issue. See original summary.

alienseer23’s picture

Issue summary: View changes
FileSize
15.1 KB
alienseer23’s picture

It might be good to consider a YOURLS service apart from the general "custom" service, so that it could be made to behave in a more YOURLS-centric fashion. For instance, in YOURLS you can pass long url, a custom keyword and a title with the shorturl call, and there is a special function for adding in a time sensitive hash for credentials, it would be great to be able to do that here.

IceCreamYou’s picture

Status: Active » Closed (works as designed)

This module is designed to be a generic URL shortener, so generally it doesn't support features specific to certain providers like link titles. (It wouldn't know how to display those titles anyway.) The main exceptions thus far are for API keys. There are no plans to expand the module in this direction, though it's great that you've found a workaround.