1
0
forked from w0bm/f0bm

possible fix for random fav behaviour

This commit is contained in:
x
2026-01-23 21:52:34 +01:00
parent 8af49b6ec1
commit 6692f32c4b
3 changed files with 67 additions and 56 deletions

View File

@@ -119,14 +119,16 @@ export default {
from items
left join tags_assign on tags_assign.item_id = items.id
left join tags on tags.id = tags_assign.tag_id
left join favorites on favorites.item_id = items.id
left join "user" on "user".id = favorites.user_id
${o.fav
? db`inner join favorites on favorites.item_id = items.id inner join "user" on "user".id = favorites.user_id`
: db`left join favorites on favorites.item_id = items.id left join "user" on "user".id = favorites.user_id`
}
left join tags_assign ta on ta.item_id = items.id and (ta.tag_id = 1 or ta.tag_id = 2)
where
${db.unsafe(modequery)}
and items.active = 'true'
${tag ? db`and tags.normalized ilike '%' || slugify(${tag}) || '%'` : db``}
${ o.fav ? db`and "user".user ilike ${'%'+user+'%'}` : db`` }
${o.fav ? db`and "user"."user" = ${user}` : db``}
${!o.fav && user ? db`and items.username ilike ${'%' + user + '%'}` : db``}
${mime ? db`and items.mime ilike ${smime}` : db``}
${!o.session && globalfilter ? db`and items.id not in (select item_id from tags_assign where item_id = items.id and (${db.unsafe(globalfilter)}))` : db``}
@@ -134,9 +136,14 @@ export default {
order by items.id desc
`;
console.log('[GETF0CK DEBUG] Query params:', { user, itemid, fav: o.fav });
console.log('[GETF0CK DEBUG] Items found:', items.length, 'Item IDs:', items.slice(0, 10).map(i => i.id));
const item = items.findIndex(i => i.id === itemid);
const actitem = items[item];
console.log('[GETF0CK DEBUG] findIndex result:', item, 'actitem exists:', !!actitem);
if (!actitem) { // sfw-check!
return {
success: false,

View File

@@ -20,6 +20,8 @@ export default (router, tpl) => {
: `/user/${query.user}/${req.params.itemid}`;
}
console.log('[AJAX DEBUG] Params:', { itemid: req.params.itemid, user: query.user, fav: query.fav, contextUrl });
const data = await f0cklib.getf0ck({
itemid: req.params.itemid,
mode: req.session.mode,
@@ -31,6 +33,8 @@ export default (router, tpl) => {
fav: query.fav === 'true'
});
console.log('[AJAX DEBUG] getf0ck result:', { success: data.success, message: data.message });
if (!data.success) {
return res.reply({
code: 404,

View File

@@ -32,7 +32,7 @@ export default router => {
where
mime ilike ${mime} and
active = 'true'
${isFav ? db`and fu."user" ilike ${user}` : db`and items.username ilike ${user}`}
${isFav ? db`and fu."user" = ${user}` : db`and items.username ilike ${user}`}
${tag ? db`and tags.normalized ilike ${'%' + tag + '%'}` : db``}
order by random()
limit 1