Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • Genesys Backend Genesys Backend
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 28
    • Issues 28
    • List
    • Boards
    • Service Desk
    • Milestones
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Genesys PGRGenesys PGR
  • Genesys BackendGenesys Backend
  • Issues
  • #457
Closed
Open
Issue created Jun 22, 2019 by Matija Obreza@mobrezaOwner

FilterCode v2

Filter encoding version 1 uses a randomly generated UUID with - removed:

private String generateShortNameV1() {
	for (int i = 0; i < 10; i++) {
		final String code = "v1" + UUID.randomUUID().toString().replace("-", "");
		// return shortName if unique
		if (shortFilterRepository.findByCode(code) == null) {
			return code;
		}
	}
	throw new RuntimeException("Failed to generate a unique filters short name in several attempts");
}

This generates filter codes like v1a37ad370d9ca4f62b3d9840094aafae9 and they are fairly long.

Shorter filter codes

We can make use of https://hashids.org/java/ to generate shorter codes with a custom salt!

Initial idea is to use the current timestamp (long value, 4b), resulting in drastically smaller unique short filter codes.

private String generateShortNameV2() {
	Hashids hashids = new Hashids("this is my salt");
	for (int i = 0; i < 10; i++) {
		String hash = hashids.encode(System.currentTimeMillis());
		final String code = "v2" + hash;
		// return shortName if unique
		if (shortFilterRepository.findByCode(code) == null) {
			return code;
		}
	}
	throw new RuntimeException("Failed to generate a unique filters short name in several attempts");
}

We could extend this to our use of UUIDs in URLs, and see if that makes a difference in URL code length.

Edited Jun 22, 2019 by Matija Obreza
Assignee
Assign to
Time tracking