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

Modify GetPost() to allow inclusion of pinned posts #113

Merged
merged 2 commits into from May 29, 2019

Conversation

joyeusenoelle
Copy link
Contributor

@joyeusenoelle joyeusenoelle commented May 28, 2019

This PR modifies the GetPost() function in database.go to add an additional parameter, includePinned. When includePinned is false, the SQL query to fetch posts will include the clause AND pinned_position IS NULL; when includePinned is true, that clause is left out.

In addition, this PR updates all calls to GetPost() to include an argument for the new position. Currently this is false everywhere but export.go, where the argument is true to ensure that all posts (including pinned posts) are exported as JSON.

I'm going with this one rather than fix-json-export because it's easier to maintain in the future (since we won't have two copies of a largely-identical function to manage).

This should resolve #112.


  • I have signed the CLA

@thebaer
Copy link
Member

thebaer commented May 28, 2019

Agreed this is the best way to go, and is consistent with how we do this sort of thing in other places. Code looks good at first glance, and I'll test soon.

rows, err := db.Query("SELECT "+postCols+" FROM posts WHERE collection_id = ? AND pinned_position IS NULL "+timeCondition+" ORDER BY created "+order+limitStr, collID)
pinnedCondition := ""
if !includePinned {
pinnedCondition = "AND pinned_position IS NULL"
Copy link

Choose a reason for hiding this comment

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

I think you will need a space on the end, AND pinned_position IS NULL . Otherwise it will run into timeCondition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The space is included in the query string on line 1096. :) It's easy enough to move it into pinnedCondition, though.

Copy link

@ghost ghost May 28, 2019

Choose a reason for hiding this comment

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

oh I totally missed that. 😊

now that I look though, does white space matter here? I mean extra. for example, if you have only timeCondition would the query having two spaces cause an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't. You can see in the deleted row that it's possible to have a double space if timeCondition is empty, and SQL doesn't seem to care at all. :)

Copy link

Choose a reason for hiding this comment

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

sweet, thanks for teaching me :)

Copy link
Member

@thebaer thebaer left a comment

Choose a reason for hiding this comment

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

Besides the func documentation, everything looks good! Just need a quick change there and then we'll get this merged.

database.go Outdated Show resolved Hide resolved
@thebaer thebaer added this to the 0.10 milestone May 29, 2019
@thebaer
Copy link
Member

thebaer commented May 29, 2019

Perfect, thanks!

@thebaer thebaer merged commit cf51fc4 into develop May 29, 2019
@thebaer thebaer deleted the fix-json-export-2 branch May 29, 2019 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

JSON Export: Not exporting pinned posts
2 participants