Giter Club home page Giter Club logo

imdb-searcher's People

Contributors

unrec avatar

Watchers

 avatar

imdb-searcher's Issues

Add field 'startYear' to type 'Season'

Update type Season:

type Season {
    season: Int
    totalEpisodes: Int
    startYear: Int
}

To get this data within' single SQL this query is to be run:

SELECT parent_id, e.season_number, max_seasons.max_episode_number, b.start_year FROM episodes e 
JOIN basics b USING(title_id)
JOIN (
	SELECT e.season_number, max(episode_number) AS max_episode_number FROM episodes e 
	WHERE e.parent_id = 944947
	GROUP BY e.season_number, parent_id
) AS max_seasons USING(season_number)
WHERE e.parent_id = 944947 AND e.episode_number=1

Corresponding kotlin-exposed query failed for mapping:

fun findSeasonsByTitleId(id: Int): List<Season> = transaction {
  val episodeMax = episode.max()
  val subQuery = EpisodeTable.slice(season, episodeMax)
	.select { parentId eq id }
	.groupBy(season, parentId).alias("sub_query")

  EpisodeTable
	.join(subQuery, INNER, season, subQuery[season])
	.join(BasicTable, INNER, BasicTable.titleId, titleId)
	.slice(parentId, season, subQuery[episodeMax], BasicTable.startYear)
	.select { (parentId eq id) and (episode eq 1) }
	.map { row ->
		Season(parentId = id,
			season = row[season],
			totalEpisodes = row[subQuery[episodeMax]],
			startYear = row[BasicTable.startYear])
		}
}

See question on stackoverflow here.

Same was tried to be resolved with this code, but it produces N+1 SQL separate queries:

fun findSeasonStartYear(season: Season): Short? = {
	val parentId = season.parentId
	val seasonNum = season.season
	val startId = episodeRepository.findStartEpisodeIdForSeason(parentId!!, seasonNum!!)
	return basicRepository.getStartYearForTitleId(startId!!)
}

fun getStartYearForTitleId(id: Int) = transaction {
	BasicTable.slice(startYear)
		.select { titleId eq id }
		.map { it[startYear] }
		.firstOrNull()
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.